Boo

Macro Operators

Details

  • Type: New Feature New Feature
  • Status: Open Open
  • Priority: Major Major
  • Resolution: Unresolved
  • Affects Version/s: 0.9.3
  • Fix Version/s: 0.9.5, 1.0
  • Component/s: Compiler, Parser
  • Labels:
    None
  • Testcase included:
    yes
  • Patch Submitted:
    Yes
  • Number of attachments :
    1

Description

Adding macro operators to the lang, so this is now legal:

a = [1,2,3]
b = 3
print a contains b

This works very much like AstMacros, we have AbstractAstOperatorMacro, which allows us to do arbitrary AST transfroms, and we also default to turning "a contains b" to "a.Contains(b)" if we can't find the relevant macro. Note that we apply pascal casing if needed.

Known issues:
1/
This is legal:
[1,2,3] contains 3

But this is not:
a = [1,2,3]
b = 3
a contains b

That is because the parser tries to read this as a macro statement, and then errors on the b.

2/ unary operators

Activity

Hide
Cedric Vivier added a comment -

Let's up discuss this feature and eventually merge it

1) Oren I think you forgot to include parser changes in your patch?

2) What is the problem with "operators-2.boo.not-implemented"?

3) I think we should implement a more booish way to declare such macros than explicitly subclassing AbstractAstOperatorMacro.
How about:

macro contains(left, right) as operator:
     return [| $left.Contains($right) |]

This would require only a small change in MacroMacro, makes it terse and look good/self-explaining imho, and does not add one more top-level macro in the namespace.

Show
Cedric Vivier added a comment - Let's up discuss this feature and eventually merge it 1) Oren I think you forgot to include parser changes in your patch? 2) What is the problem with "operators-2.boo.not-implemented"? 3) I think we should implement a more booish way to declare such macros than explicitly subclassing AbstractAstOperatorMacro. How about:
macro contains(left, right) as operator:
     return [| $left.Contains($right) |]
This would require only a small change in MacroMacro, makes it terse and look good/self-explaining imho, and does not add one more top-level macro in the namespace.
Hide
Tristan Zajonc added a comment -

Does this support symbolic infix operators, such as ".+"? It would be nice if it did to allow for elementwise and objectwise operators on collections, for instance.

Show
Tristan Zajonc added a comment - Does this support symbolic infix operators, such as ".+"? It would be nice if it did to allow for elementwise and objectwise operators on collections, for instance.

People

Vote (2)
Watch (1)

Dates

  • Created:
    Updated: