[jira] Created: (BOO-1146) Macro definition arguments

View: New views
18 Messages — Rating Filter:   Alert me  

[jira] Created: (BOO-1146) Macro definition arguments

by JIRA jira@codehaus.org :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Macro definition arguments
--------------------------

                 Key: BOO-1146
                 URL: http://jira.codehaus.org/browse/BOO-1146
             Project: Boo
          Issue Type: New Feature
          Components: Compiler
    Affects Versions: 0.9
            Reporter: Cedric Vivier
            Assignee: Cedric Vivier
             Fix For: 0.9.1


Current macro macro: syntax is a little unfriendly when it comes to handling arguments, and also lead to a lot of code duplication wrt argument checks.
It would be nice if we could define macro arguments directly through macro 'macro' that would do the work for us.

We could write this:

{code}
macro printNameTimes(text as string, count as int):
        for i in range(0, count):
                yield [| print $text |]

printTimes "cool", 3
{code}

Instead of this:

{code}
macro printTimes:
        if printTimes.Arguments.Count != 2:
                raise "Usage: printTimes <text>, <count>"
        if not printTimes.Arguments[0] isa StringLiteralExpression:
                raise "Usage: printTimes <text>, <count> : `text` must be string literal"
        if not printTimes.Arguments[1] isa IntegerLiteralExpression:
                raise "Usage: printTimes <text>, <count> : `text` must be int literal"

        text = cast(StringLiteralExpression, printTimes.Arguments[0]).Value
        count = cast(IntegerLiteralExpression, printTimes.Arguments[1]).Value
        for i in range(0, count):
                yield [| print $text |]
{code}


Also we could write this:

{code}
macro when(condition):
        yield [|
                if $condition:
                        $when.Body
        |]
{code}

Instead of this:

{code}
macro when:
        if when.Arguments.Count != 1:
                raise "Usage: when <expression>"
        yield [|
                if $(when.Arguments[0]):
                        $when.Body
        |]
{code}


--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://jira.codehaus.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

       

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



[jira] Updated: (BOO-1146) Macro definition arguments

by JIRA jira@codehaus.org :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


     [ http://jira.codehaus.org/browse/BOO-1146?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Cedric Vivier updated BOO-1146:
-------------------------------

    Description:
Current macro macro: syntax is a little unfriendly when it comes to handling arguments, and also lead to a lot of code duplication wrt argument checks.
It would be nice if we could define macro arguments directly through macro 'macro' that would do the work for us.

We could write this:

{code}
macro printTimes(text as string, count as int):
        for i in range(0, count):
                yield [| print $text |]

printTimes "cool", 3
{code}

Instead of this:

{code}
macro printTimes:
        if printTimes.Arguments.Count != 2:
                raise "Usage: printTimes <text>, <count>"
        if not printTimes.Arguments[0] isa StringLiteralExpression:
                raise "Usage: printTimes <text>, <count> : `text` must be string literal"
        if not printTimes.Arguments[1] isa IntegerLiteralExpression:
                raise "Usage: printTimes <text>, <count> : `text` must be int literal"

        text = cast(StringLiteralExpression, printTimes.Arguments[0]).Value
        count = cast(IntegerLiteralExpression, printTimes.Arguments[1]).Value
        for i in range(0, count):
                yield [| print $text |]
{code}


Also we could write this:

{code}
macro when(condition):
        yield [|
                if $condition:
                        $when.Body
        |]
{code}

Instead of this:

{code}
macro when:
        if when.Arguments.Count != 1:
                raise "Usage: when <expression>"
        yield [|
                if $(when.Arguments[0]):
                        $when.Body
        |]
{code}


  was:
Current macro macro: syntax is a little unfriendly when it comes to handling arguments, and also lead to a lot of code duplication wrt argument checks.
It would be nice if we could define macro arguments directly through macro 'macro' that would do the work for us.

We could write this:

{code}
macro printNameTimes(text as string, count as int):
        for i in range(0, count):
                yield [| print $text |]

printTimes "cool", 3
{code}

Instead of this:

{code}
macro printTimes:
        if printTimes.Arguments.Count != 2:
                raise "Usage: printTimes <text>, <count>"
        if not printTimes.Arguments[0] isa StringLiteralExpression:
                raise "Usage: printTimes <text>, <count> : `text` must be string literal"
        if not printTimes.Arguments[1] isa IntegerLiteralExpression:
                raise "Usage: printTimes <text>, <count> : `text` must be int literal"

        text = cast(StringLiteralExpression, printTimes.Arguments[0]).Value
        count = cast(IntegerLiteralExpression, printTimes.Arguments[1]).Value
        for i in range(0, count):
                yield [| print $text |]
{code}


Also we could write this:

{code}
macro when(condition):
        yield [|
                if $condition:
                        $when.Body
        |]
{code}

Instead of this:

{code}
macro when:
        if when.Arguments.Count != 1:
                raise "Usage: when <expression>"
        yield [|
                if $(when.Arguments[0]):
                        $when.Body
        |]
{code}



> Macro definition arguments
> --------------------------
>
>                 Key: BOO-1146
>                 URL: http://jira.codehaus.org/browse/BOO-1146
>             Project: Boo
>          Issue Type: New Feature
>          Components: Compiler
>    Affects Versions: 0.9
>            Reporter: Cedric Vivier
>            Assignee: Cedric Vivier
>             Fix For: 0.9.1
>
>
> Current macro macro: syntax is a little unfriendly when it comes to handling arguments, and also lead to a lot of code duplication wrt argument checks.
> It would be nice if we could define macro arguments directly through macro 'macro' that would do the work for us.
> We could write this:
> {code}
> macro printTimes(text as string, count as int):
> for i in range(0, count):
> yield [| print $text |]
> printTimes "cool", 3
> {code}
> Instead of this:
> {code}
> macro printTimes:
> if printTimes.Arguments.Count != 2:
> raise "Usage: printTimes <text>, <count>"
> if not printTimes.Arguments[0] isa StringLiteralExpression:
> raise "Usage: printTimes <text>, <count> : `text` must be string literal"
> if not printTimes.Arguments[1] isa IntegerLiteralExpression:
> raise "Usage: printTimes <text>, <count> : `text` must be int literal"
> text = cast(StringLiteralExpression, printTimes.Arguments[0]).Value
> count = cast(IntegerLiteralExpression, printTimes.Arguments[1]).Value
> for i in range(0, count):
> yield [| print $text |]
> {code}
> Also we could write this:
> {code}
> macro when(condition):
> yield [|
> if $condition:
> $when.Body
> |]
> {code}
> Instead of this:
> {code}
> macro when:
> if when.Arguments.Count != 1:
> raise "Usage: when <expression>"
> yield [|
> if $(when.Arguments[0]):
> $when.Body
> |]
> {code}

--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://jira.codehaus.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

       

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



[jira] Commented: (BOO-1146) Macro definition arguments

by JIRA jira@codehaus.org :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


    [ http://jira.codehaus.org/browse/BOO-1146?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=163116#action_163116 ]

Rodrigo B. de Oliveira commented on BOO-1146:
---------------------------------------------

The text misrepresents the way macros are expressed Today. The first macro could be:

{code}
macro printTimes:
        case [| printTimes $(StringLiteralExpression(Value: text)), $(IntegerLiteralExpression(Value: count)) |]:
                for i in range(count):
                        yield [| print $text |]
{code}


> Macro definition arguments
> --------------------------
>
>                 Key: BOO-1146
>                 URL: http://jira.codehaus.org/browse/BOO-1146
>             Project: Boo
>          Issue Type: New Feature
>          Components: Compiler
>    Affects Versions: 0.9
>            Reporter: Cedric Vivier
>            Assignee: Cedric Vivier
>             Fix For: 0.9.1
>
>
> Current macro macro: syntax is a little unfriendly when it comes to handling arguments, and also lead to a lot of code duplication wrt argument checks.
> It would be nice if we could define macro arguments directly through macro 'macro' that would do the work for us.
> We could write this:
> {code}
> macro printTimes(text as string, count as int):
> for i in range(0, count):
> yield [| print $text |]
> printTimes "cool", 3
> {code}
> Instead of this:
> {code}
> macro printTimes:
> if printTimes.Arguments.Count != 2:
> raise "Usage: printTimes <text>, <count>"
> if not printTimes.Arguments[0] isa StringLiteralExpression:
> raise "Usage: printTimes <text>, <count> : `text` must be string literal"
> if not printTimes.Arguments[1] isa IntegerLiteralExpression:
> raise "Usage: printTimes <text>, <count> : `text` must be int literal"
> text = cast(StringLiteralExpression, printTimes.Arguments[0]).Value
> count = cast(IntegerLiteralExpression, printTimes.Arguments[1]).Value
> for i in range(0, count):
> yield [| print $text |]
> {code}
> Also we could write this:
> {code}
> macro when(condition):
> yield [|
> if $condition:
> $when.Body
> |]
> {code}
> Instead of this:
> {code}
> macro when:
> if when.Arguments.Count != 1:
> raise "Usage: when <expression>"
> yield [|
> if $(when.Arguments[0]):
> $when.Body
> |]
> {code}

--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://jira.codehaus.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

       

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



[jira] Commented: (BOO-1146) Macro definition arguments

by JIRA jira@codehaus.org :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


    [ http://jira.codehaus.org/browse/BOO-1146?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=163124#action_163124 ]

Cedric Vivier commented on BOO-1146:
------------------------------------

Oh yeah nice :)
I did not think about pattern matching for such simple patterns, but well indeed it could be implemented that way by macro `macro`.

The point still, is or isn't the syntax proposal a good idea?
I mean pattern matching is really nice of course but for such simple patterns it seems a little overkill to have to write these isn't?
Also the new syntax can potentially provide better error reporting (as in display the 'macro' arguments like "Usage: macroname arg1 arg2..")

The nice thing about implementing this syntax with pattern matching would be to be able to write macro overloads in isolation:

{code}
macro option(name as string, value as string):
         yield [| print "<string name="${$name}">${$value}</string>"  |]

macro option(name as string, value as int):
         yield [| print "<integer name="${$name}">${$value}</string>"  |]
{code}


would produce simply two cases merged in the same 'option' macro :)

{code}
macro option:
        case [| option $(StringLiteralExpression(Value: name)), $(StringLiteralExpression(Value: value)) |]:
               yield [| print "<integer name="${$name}">${$value}</string>"  |]

        case [| option $(StringLiteralExpression(Value: name)), $(IntegerLiteralExpression(Value: value)) |]:
               yield [| print "<integer name="${$name}">${$value}</integer>"  |]
{code}


> Macro definition arguments
> --------------------------
>
>                 Key: BOO-1146
>                 URL: http://jira.codehaus.org/browse/BOO-1146
>             Project: Boo
>          Issue Type: New Feature
>          Components: Compiler
>    Affects Versions: 0.9
>            Reporter: Cedric Vivier
>            Assignee: Cedric Vivier
>             Fix For: 0.9.1
>
>
> Current macro macro: syntax is a little unfriendly when it comes to handling arguments, and also lead to a lot of code duplication wrt argument checks.
> It would be nice if we could define macro arguments directly through macro 'macro' that would do the work for us.
> We could write this:
> {code}
> macro printTimes(text as string, count as int):
> for i in range(0, count):
> yield [| print $text |]
> printTimes "cool", 3
> {code}
> Instead of this:
> {code}
> macro printTimes:
> if printTimes.Arguments.Count != 2:
> raise "Usage: printTimes <text>, <count>"
> if not printTimes.Arguments[0] isa StringLiteralExpression:
> raise "Usage: printTimes <text>, <count> : `text` must be string literal"
> if not printTimes.Arguments[1] isa IntegerLiteralExpression:
> raise "Usage: printTimes <text>, <count> : `text` must be int literal"
> text = cast(StringLiteralExpression, printTimes.Arguments[0]).Value
> count = cast(IntegerLiteralExpression, printTimes.Arguments[1]).Value
> for i in range(0, count):
> yield [| print $text |]
> {code}
> Also we could write this:
> {code}
> macro when(condition):
> yield [|
> if $condition:
> $when.Body
> |]
> {code}
> Instead of this:
> {code}
> macro when:
> if when.Arguments.Count != 1:
> raise "Usage: when <expression>"
> yield [|
> if $(when.Arguments[0]):
> $when.Body
> |]
> {code}

--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://jira.codehaus.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

       

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



[jira] Issue Comment Edited: (BOO-1146) Macro definition arguments

by JIRA jira@codehaus.org :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


    [ http://jira.codehaus.org/browse/BOO-1146?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=163124#action_163124 ]

Cedric Vivier edited comment on BOO-1146 at 1/29/09 10:28 AM:
--------------------------------------------------------------

Oh yeah nice :)
I did not think about pattern matching for such simple patterns, but well indeed it could be implemented that way by macro `macro`.

The point still, is or isn't the syntax proposal a good idea?
I mean pattern matching is really nice of course but for such simple patterns it seems a little overkill to have to write these isn't it?
Also the new syntax can potentially provide better error reporting (as in display the 'macro' arguments like "Usage: macroname arg1 arg2..")

The nice thing about implementing this syntax with pattern matching would be to be able to write macro overloads in isolation:

{code}
macro option(name as string, value as string):
         yield [| print "<string name="${$name}">${$value}</string>"  |]

macro option(name as string, value as int):
         yield [| print "<integer name="${$name}">${$value}</string>"  |]
{code}


would produce simply two cases merged in the same 'option' macro :)

{code}
macro option:
        case [| option $(StringLiteralExpression(Value: name)), $(StringLiteralExpression(Value: value)) |]:
               yield [| print "<integer name="${$name}">${$value}</string>"  |]

        case [| option $(StringLiteralExpression(Value: name)), $(IntegerLiteralExpression(Value: value)) |]:
               yield [| print "<integer name="${$name}">${$value}</integer>"  |]
{code}


      was (Author: cedricv):
    Oh yeah nice :)
I did not think about pattern matching for such simple patterns, but well indeed it could be implemented that way by macro `macro`.

The point still, is or isn't the syntax proposal a good idea?
I mean pattern matching is really nice of course but for such simple patterns it seems a little overkill to have to write these isn't?
Also the new syntax can potentially provide better error reporting (as in display the 'macro' arguments like "Usage: macroname arg1 arg2..")

The nice thing about implementing this syntax with pattern matching would be to be able to write macro overloads in isolation:

{code}
macro option(name as string, value as string):
         yield [| print "<string name="${$name}">${$value}</string>"  |]

macro option(name as string, value as int):
         yield [| print "<integer name="${$name}">${$value}</string>"  |]
{code}


would produce simply two cases merged in the same 'option' macro :)

{code}
macro option:
        case [| option $(StringLiteralExpression(Value: name)), $(StringLiteralExpression(Value: value)) |]:
               yield [| print "<integer name="${$name}">${$value}</string>"  |]

        case [| option $(StringLiteralExpression(Value: name)), $(IntegerLiteralExpression(Value: value)) |]:
               yield [| print "<integer name="${$name}">${$value}</integer>"  |]
{code}

 

> Macro definition arguments
> --------------------------
>
>                 Key: BOO-1146
>                 URL: http://jira.codehaus.org/browse/BOO-1146
>             Project: Boo
>          Issue Type: New Feature
>          Components: Compiler
>    Affects Versions: 0.9
>            Reporter: Cedric Vivier
>            Assignee: Cedric Vivier
>             Fix For: 0.9.1
>
>
> Current macro macro: syntax is a little unfriendly when it comes to handling arguments, and also lead to a lot of code duplication wrt argument checks.
> It would be nice if we could define macro arguments directly through macro 'macro' that would do the work for us.
> We could write this:
> {code}
> macro printTimes(text as string, count as int):
> for i in range(0, count):
> yield [| print $text |]
> printTimes "cool", 3
> {code}
> Instead of this:
> {code}
> macro printTimes:
> if printTimes.Arguments.Count != 2:
> raise "Usage: printTimes <text>, <count>"
> if not printTimes.Arguments[0] isa StringLiteralExpression:
> raise "Usage: printTimes <text>, <count> : `text` must be string literal"
> if not printTimes.Arguments[1] isa IntegerLiteralExpression:
> raise "Usage: printTimes <text>, <count> : `text` must be int literal"
> text = cast(StringLiteralExpression, printTimes.Arguments[0]).Value
> count = cast(IntegerLiteralExpression, printTimes.Arguments[1]).Value
> for i in range(0, count):
> yield [| print $text |]
> {code}
> Also we could write this:
> {code}
> macro when(condition):
> yield [|
> if $condition:
> $when.Body
> |]
> {code}
> Instead of this:
> {code}
> macro when:
> if when.Arguments.Count != 1:
> raise "Usage: when <expression>"
> yield [|
> if $(when.Arguments[0]):
> $when.Body
> |]
> {code}

--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://jira.codehaus.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

       

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



[jira] Issue Comment Edited: (BOO-1146) Macro definition arguments

by JIRA jira@codehaus.org :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


    [ http://jira.codehaus.org/browse/BOO-1146?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=163124#action_163124 ]

Cedric Vivier edited comment on BOO-1146 at 1/29/09 10:32 AM:
--------------------------------------------------------------

Oh yeah nice :)
I did not think about pattern matching for such simple patterns, but well indeed it could be implemented that way by macro `macro`.

The point still, is or isn't the syntax proposal a good idea?
I mean pattern matching is really nice of course but for such simple patterns it seems a little overkill to have to write these isn't it?
Also the new syntax can potentially provide better error reporting (as in display the 'macro' arguments like "Usage: macroname arg1 arg2..")

The nice thing about implementing this syntax with pattern matching would be to be able to write macro overloads in isolation:

{code}
macro option(name as string, value as string):
         yield [| print "<string name="${$name}">${$value}</string>"  |]

macro option(name as string, value as int):
         yield [| print "<integer name="${$name}">${$value}</string>"  |]
{code}


would produce simply two cases merged in the same 'option' macro :)

{code}
macro option:
        case [| option $(StringLiteralExpression(Value: name)), $(StringLiteralExpression(Value: value)) |]:
               yield [| print "<string name="${$name}">${$value}</string>"  |]

        case [| option $(StringLiteralExpression(Value: name)), $(IntegerLiteralExpression(Value: value)) |]:
               yield [| print "<integer name="${$name}">${$value}</integer>"  |]
{code}


      was (Author: cedricv):
    Oh yeah nice :)
I did not think about pattern matching for such simple patterns, but well indeed it could be implemented that way by macro `macro`.

The point still, is or isn't the syntax proposal a good idea?
I mean pattern matching is really nice of course but for such simple patterns it seems a little overkill to have to write these isn't it?
Also the new syntax can potentially provide better error reporting (as in display the 'macro' arguments like "Usage: macroname arg1 arg2..")

The nice thing about implementing this syntax with pattern matching would be to be able to write macro overloads in isolation:

{code}
macro option(name as string, value as string):
         yield [| print "<string name="${$name}">${$value}</string>"  |]

macro option(name as string, value as int):
         yield [| print "<integer name="${$name}">${$value}</string>"  |]
{code}


would produce simply two cases merged in the same 'option' macro :)

{code}
macro option:
        case [| option $(StringLiteralExpression(Value: name)), $(StringLiteralExpression(Value: value)) |]:
               yield [| print "<integer name="${$name}">${$value}</string>"  |]

        case [| option $(StringLiteralExpression(Value: name)), $(IntegerLiteralExpression(Value: value)) |]:
               yield [| print "<integer name="${$name}">${$value}</integer>"  |]
{code}

 

> Macro definition arguments
> --------------------------
>
>                 Key: BOO-1146
>                 URL: http://jira.codehaus.org/browse/BOO-1146
>             Project: Boo
>          Issue Type: New Feature
>          Components: Compiler
>    Affects Versions: 0.9
>            Reporter: Cedric Vivier
>            Assignee: Cedric Vivier
>             Fix For: 0.9.1
>
>
> Current macro macro: syntax is a little unfriendly when it comes to handling arguments, and also lead to a lot of code duplication wrt argument checks.
> It would be nice if we could define macro arguments directly through macro 'macro' that would do the work for us.
> We could write this:
> {code}
> macro printTimes(text as string, count as int):
> for i in range(0, count):
> yield [| print $text |]
> printTimes "cool", 3
> {code}
> Instead of this:
> {code}
> macro printTimes:
> if printTimes.Arguments.Count != 2:
> raise "Usage: printTimes <text>, <count>"
> if not printTimes.Arguments[0] isa StringLiteralExpression:
> raise "Usage: printTimes <text>, <count> : `text` must be string literal"
> if not printTimes.Arguments[1] isa IntegerLiteralExpression:
> raise "Usage: printTimes <text>, <count> : `text` must be int literal"
> text = cast(StringLiteralExpression, printTimes.Arguments[0]).Value
> count = cast(IntegerLiteralExpression, printTimes.Arguments[1]).Value
> for i in range(0, count):
> yield [| print $text |]
> {code}
> Also we could write this:
> {code}
> macro when(condition):
> yield [|
> if $condition:
> $when.Body
> |]
> {code}
> Instead of this:
> {code}
> macro when:
> if when.Arguments.Count != 1:
> raise "Usage: when <expression>"
> yield [|
> if $(when.Arguments[0]):
> $when.Body
> |]
> {code}

--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://jira.codehaus.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

       

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



[jira] Commented: (BOO-1146) Macro definition arguments

by JIRA jira@codehaus.org :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


    [ http://jira.codehaus.org/browse/BOO-1146?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=163182#action_163182 ]

Cedric Vivier commented on BOO-1146:
------------------------------------

Enumerable or array argument types should be possible.
As well as argument attributes, such as [body] to define what can be inside the macro's body.

Testcase:
{code}
macro printOnlyCorrectlySpelled([body] sentences as string*):
     for sentence in sentences:
          if SpellCheck(sentence):
                yield [| print $sentence |]

printOnlyCorrectlySpelled:
     "one long big sentence..............."
     "one anoother......................................"
{code}


> Macro definition arguments
> --------------------------
>
>                 Key: BOO-1146
>                 URL: http://jira.codehaus.org/browse/BOO-1146
>             Project: Boo
>          Issue Type: New Feature
>          Components: Compiler
>    Affects Versions: 0.9
>            Reporter: Cedric Vivier
>            Assignee: Cedric Vivier
>             Fix For: 0.9.1
>
>
> Current macro macro: syntax is a little unfriendly when it comes to handling arguments, and also lead to a lot of code duplication wrt argument checks.
> It would be nice if we could define macro arguments directly through macro 'macro' that would do the work for us.
> We could write this:
> {code}
> macro printTimes(text as string, count as int):
> for i in range(0, count):
> yield [| print $text |]
> printTimes "cool", 3
> {code}
> Instead of this:
> {code}
> macro printTimes:
> if printTimes.Arguments.Count != 2:
> raise "Usage: printTimes <text>, <count>"
> if not printTimes.Arguments[0] isa StringLiteralExpression:
> raise "Usage: printTimes <text>, <count> : `text` must be string literal"
> if not printTimes.Arguments[1] isa IntegerLiteralExpression:
> raise "Usage: printTimes <text>, <count> : `text` must be int literal"
> text = cast(StringLiteralExpression, printTimes.Arguments[0]).Value
> count = cast(IntegerLiteralExpression, printTimes.Arguments[1]).Value
> for i in range(0, count):
> yield [| print $text |]
> {code}
> Also we could write this:
> {code}
> macro when(condition):
> yield [|
> if $condition:
> $when.Body
> |]
> {code}
> Instead of this:
> {code}
> macro when:
> if when.Arguments.Count != 1:
> raise "Usage: when <expression>"
> yield [|
> if $(when.Arguments[0]):
> $when.Body
> |]
> {code}

--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://jira.codehaus.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

       

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



[jira] Work started: (BOO-1146) Macro definition arguments

by JIRA jira@codehaus.org :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


     [ http://jira.codehaus.org/browse/BOO-1146?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Work on BOO-1146 started by Cedric Vivier.

> Macro definition arguments
> --------------------------
>
>                 Key: BOO-1146
>                 URL: http://jira.codehaus.org/browse/BOO-1146
>             Project: Boo
>          Issue Type: New Feature
>          Components: Compiler
>    Affects Versions: 0.9
>            Reporter: Cedric Vivier
>            Assignee: Cedric Vivier
>             Fix For: 0.9.1
>
>
> Current macro macro: syntax is a little unfriendly when it comes to handling arguments, and also lead to a lot of code duplication wrt argument checks.
> It would be nice if we could define macro arguments directly through macro 'macro' that would do the work for us.
> We could write this:
> {code}
> macro printTimes(text as string, count as int):
> for i in range(0, count):
> yield [| print $text |]
> printTimes "cool", 3
> {code}
> Instead of this:
> {code}
> macro printTimes:
> if printTimes.Arguments.Count != 2:
> raise "Usage: printTimes <text>, <count>"
> if not printTimes.Arguments[0] isa StringLiteralExpression:
> raise "Usage: printTimes <text>, <count> : `text` must be string literal"
> if not printTimes.Arguments[1] isa IntegerLiteralExpression:
> raise "Usage: printTimes <text>, <count> : `text` must be int literal"
> text = cast(StringLiteralExpression, printTimes.Arguments[0]).Value
> count = cast(IntegerLiteralExpression, printTimes.Arguments[1]).Value
> for i in range(0, count):
> yield [| print $text |]
> {code}
> Also we could write this:
> {code}
> macro when(condition):
> yield [|
> if $condition:
> $when.Body
> |]
> {code}
> Instead of this:
> {code}
> macro when:
> if when.Arguments.Count != 1:
> raise "Usage: when <expression>"
> yield [|
> if $(when.Arguments[0]):
> $when.Body
> |]
> {code}

--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://jira.codehaus.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

       

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



[jira] Issue Comment Edited: (BOO-1146) Macro definition arguments

by JIRA jira@codehaus.org :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


    [ http://jira.codehaus.org/browse/BOO-1146?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=163182#action_163182 ]

Cedric Vivier edited comment on BOO-1146 at 2/2/09 11:37 AM:
-------------------------------------------------------------

Macro expected body can be defined when last argument name is `body`.
Also enumerable (or array) argument type is allowed for last argument (whether or not `body`), this means variable number of arguments (or variable number of statements for `body` argument) is allowed, as long as it matches the specified type (if any).

E.g:
{code}
macro printOnlyCorrectlySpelled(body as string*):
     for sentence in body:
          if SpellCheck(sentence):
                yield [| print $sentence |]

printOnlyCorrectlySpelled:
     "one long big sentence..............."
     "one anoother......................................"
{code}


      was (Author: cedricv):
    Enumerable or array argument types should be possible.
As well as argument attributes, such as [body] to define what can be inside the macro's body.

Testcase:
{code}
macro printOnlyCorrectlySpelled([body] sentences as string*):
     for sentence in sentences:
          if SpellCheck(sentence):
                yield [| print $sentence |]

printOnlyCorrectlySpelled:
     "one long big sentence..............."
     "one anoother......................................"
{code}

 

> Macro definition arguments
> --------------------------
>
>                 Key: BOO-1146
>                 URL: http://jira.codehaus.org/browse/BOO-1146
>             Project: Boo
>          Issue Type: New Feature
>          Components: Compiler
>    Affects Versions: 0.9
>            Reporter: Cedric Vivier
>            Assignee: Cedric Vivier
>             Fix For: 0.9.1
>
>
> Current macro macro: syntax is a little unfriendly when it comes to handling arguments, and also lead to a lot of code duplication wrt argument checks.
> It would be nice if we could define macro arguments directly through macro 'macro' that would do the work for us.
> We could write this:
> {code}
> macro printTimes(text as string, count as int):
> for i in range(0, count):
> yield [| print $text |]
> printTimes "cool", 3
> {code}
> Instead of this:
> {code}
> macro printTimes:
> if printTimes.Arguments.Count != 2:
> raise "Usage: printTimes <text>, <count>"
> if not printTimes.Arguments[0] isa StringLiteralExpression:
> raise "Usage: printTimes <text>, <count> : `text` must be string literal"
> if not printTimes.Arguments[1] isa IntegerLiteralExpression:
> raise "Usage: printTimes <text>, <count> : `text` must be int literal"
> text = cast(StringLiteralExpression, printTimes.Arguments[0]).Value
> count = cast(IntegerLiteralExpression, printTimes.Arguments[1]).Value
> for i in range(0, count):
> yield [| print $text |]
> {code}
> Also we could write this:
> {code}
> macro when(condition):
> yield [|
> if $condition:
> $when.Body
> |]
> {code}
> Instead of this:
> {code}
> macro when:
> if when.Arguments.Count != 1:
> raise "Usage: when <expression>"
> yield [|
> if $(when.Arguments[0]):
> $when.Body
> |]
> {code}

--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://jira.codehaus.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

       

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



[jira] Commented: (BOO-1146) Macro definition arguments

by JIRA jira@codehaus.org :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


    [ http://jira.codehaus.org/browse/BOO-1146?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=163585#action_163585 ]

Cedric Vivier commented on BOO-1146:
------------------------------------

Testcase (macro-arguments-1.boo):
{code}
"""
Boo
Rocks!
So true!
Assertion that `a == b` is true failed!
Assertion that expressions `a.ToString()` and `bool.FalseString` are equal failed!
"""

import Boo.Lang.Compiler.Ast
import Boo.Lang.PatternMatching


macro printYOnlyIfZIs42(x as string, y as string, z as long):
        yield [| print $x |]
        yield [| print $y |] if z == 42


macro printOnlyIfTrue(text as string, boolean as bool):
        yield [| print $text |] if boolean


macro assertTrue(condition as ConditionalExpression):
        yield [| print "Assertion that `${$(condition.ToCodeString())}` is true failed!" if not $condition |]

macro assertEqual(a,b):
        yield [|
                if $a != $b:
                        print "Assertion that expressions `${$(a.ToCodeString())}` and `${$(b.ToCodeString())}` are equal failed!"
        |]


printYOnlyIfZIs42 "Boo", "Rocks!", 42L

printOnlyIfTrue "So false!", false
printOnlyIfTrue "So true!", true

a = true
b = false
assertTrue a != b
assertTrue a == b

assertEqual a.ToString(), bool.TrueString
assertEqual a.ToString(), bool.FalseString
{code}

(now working)


> Macro definition arguments
> --------------------------
>
>                 Key: BOO-1146
>                 URL: http://jira.codehaus.org/browse/BOO-1146
>             Project: Boo
>          Issue Type: New Feature
>          Components: Compiler
>    Affects Versions: 0.9
>            Reporter: Cedric Vivier
>            Assignee: Cedric Vivier
>             Fix For: 0.9.1
>
>
> Current macro macro: syntax is a little unfriendly when it comes to handling arguments, and also lead to a lot of code duplication wrt argument checks.
> It would be nice if we could define macro arguments directly through macro 'macro' that would do the work for us.
> We could write this:
> {code}
> macro printTimes(text as string, count as int):
> for i in range(0, count):
> yield [| print $text |]
> printTimes "cool", 3
> {code}
> Instead of this:
> {code}
> macro printTimes:
> if printTimes.Arguments.Count != 2:
> raise "Usage: printTimes <text>, <count>"
> if not printTimes.Arguments[0] isa StringLiteralExpression:
> raise "Usage: printTimes <text>, <count> : `text` must be string literal"
> if not printTimes.Arguments[1] isa IntegerLiteralExpression:
> raise "Usage: printTimes <text>, <count> : `text` must be int literal"
> text = cast(StringLiteralExpression, printTimes.Arguments[0]).Value
> count = cast(IntegerLiteralExpression, printTimes.Arguments[1]).Value
> for i in range(0, count):
> yield [| print $text |]
> {code}
> Also we could write this:
> {code}
> macro when(condition):
> yield [|
> if $condition:
> $when.Body
> |]
> {code}
> Instead of this:
> {code}
> macro when:
> if when.Arguments.Count != 1:
> raise "Usage: when <expression>"
> yield [|
> if $(when.Arguments[0]):
> $when.Body
> |]
> {code}

--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://jira.codehaus.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

       

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



[jira] Issue Comment Edited: (BOO-1146) Macro definition arguments

by JIRA jira@codehaus.org :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


    [ http://jira.codehaus.org/browse/BOO-1146?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=163585#action_163585 ]

Cedric Vivier edited comment on BOO-1146 at 2/3/09 2:56 AM:
------------------------------------------------------------

Testcase (macro-arguments-1.boo):
{code}
"""
Boo
Rocks!
So true!
Assertion that `b` is true failed!
Assertion that expressions `a.ToString()` and `bool.FalseString` are equal failed!
Regex 'foo' matched string 'foofoo'
86423 seconds (1.00:00:23) is longer than one day.
"""
import Boo.Lang.PatternMatching

macro printYOnlyIfZIs42(x as string, y as string, z as long):
        yield [| print $x |]
        yield [| print $y |] if z == 42


macro printOnlyIfTrue(text as string, boolean as bool):
        yield [| print $text |] if boolean


macro assertTrue(variable as Boo.Lang.Compiler.Ast.ReferenceExpression):
        yield [| print "Assertion that `${$(variable.Name)}` is true failed!" if not $variable |]


macro assertEqual(a,b):
        yield [|
                if $a != $b:
                        print "Assertion that expressions `${$(a.ToCodeString())}` and `${$(b.ToCodeString())}` are equal failed!"
        |]


macro matchRegex(pattern as regex, text as string):
        yield [| print "Regex '${$pattern}' matched string '${$text}'" |] if pattern.IsMatch(text)


macro longerThanOneDay(duration as timespan):
        yield [| print "${$(duration.TotalSeconds)} seconds (${$duration}) is longer than one day." |] if duration > 1d


printYOnlyIfZIs42 "Boo", "Rocks!", 42L

printOnlyIfTrue "So false!", false
printOnlyIfTrue "So true!", true

a = true
b = false
assertTrue a
assertTrue b

assertEqual a.ToString(), bool.TrueString
assertEqual a.ToString(), bool.FalseString

matchRegex /foo/, "foofoo"
matchRegex /foo/, "barbar"

longerThanOneDay 86423s
longerThanOneDay 23h
{code}


      was (Author: cedricv):
    Testcase (macro-arguments-1.boo):
{code}
"""
Boo
Rocks!
So true!
Assertion that `a == b` is true failed!
Assertion that expressions `a.ToString()` and `bool.FalseString` are equal failed!
"""

import Boo.Lang.Compiler.Ast
import Boo.Lang.PatternMatching


macro printYOnlyIfZIs42(x as string, y as string, z as long):
        yield [| print $x |]
        yield [| print $y |] if z == 42


macro printOnlyIfTrue(text as string, boolean as bool):
        yield [| print $text |] if boolean


macro assertTrue(condition as ConditionalExpression):
        yield [| print "Assertion that `${$(condition.ToCodeString())}` is true failed!" if not $condition |]

macro assertEqual(a,b):
        yield [|
                if $a != $b:
                        print "Assertion that expressions `${$(a.ToCodeString())}` and `${$(b.ToCodeString())}` are equal failed!"
        |]


printYOnlyIfZIs42 "Boo", "Rocks!", 42L

printOnlyIfTrue "So false!", false
printOnlyIfTrue "So true!", true

a = true
b = false
assertTrue a != b
assertTrue a == b

assertEqual a.ToString(), bool.TrueString
assertEqual a.ToString(), bool.FalseString
{code}

(now working)

 

> Macro definition arguments
> --------------------------
>
>                 Key: BOO-1146
>                 URL: http://jira.codehaus.org/browse/BOO-1146
>             Project: Boo
>          Issue Type: New Feature
>          Components: Compiler
>    Affects Versions: 0.9
>            Reporter: Cedric Vivier
>            Assignee: Cedric Vivier
>             Fix For: 0.9.1
>
>
> Current macro macro: syntax is a little unfriendly when it comes to handling arguments, and also lead to a lot of code duplication wrt argument checks.
> It would be nice if we could define macro arguments directly through macro 'macro' that would do the work for us.
> We could write this:
> {code}
> macro printTimes(text as string, count as int):
> for i in range(0, count):
> yield [| print $text |]
> printTimes "cool", 3
> {code}
> Instead of this:
> {code}
> macro printTimes:
> if printTimes.Arguments.Count != 2:
> raise "Usage: printTimes <text>, <count>"
> if not printTimes.Arguments[0] isa StringLiteralExpression:
> raise "Usage: printTimes <text>, <count> : `text` must be string literal"
> if not printTimes.Arguments[1] isa IntegerLiteralExpression:
> raise "Usage: printTimes <text>, <count> : `text` must be int literal"
> text = cast(StringLiteralExpression, printTimes.Arguments[0]).Value
> count = cast(IntegerLiteralExpression, printTimes.Arguments[1]).Value
> for i in range(0, count):
> yield [| print $text |]
> {code}
> Also we could write this:
> {code}
> macro when(condition):
> yield [|
> if $condition:
> $when.Body
> |]
> {code}
> Instead of this:
> {code}
> macro when:
> if when.Arguments.Count != 1:
> raise "Usage: when <expression>"
> yield [|
> if $(when.Arguments[0]):
> $when.Body
> |]
> {code}

--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://jira.codehaus.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

       

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



[jira] Commented: (BOO-1146) Macro definition arguments

by JIRA jira@codehaus.org :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


    [ http://jira.codehaus.org/browse/BOO-1146?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=163667#action_163667 ]

Cedric Vivier commented on BOO-1146:
------------------------------------

Initial support (handles testcase macro-arguments-1 above) landed in rev. 3229+3230

Next steps:
- `body` argument to match against macro.Body
- enumerable/arrray argument types
- macro overloads


> Macro definition arguments
> --------------------------
>
>                 Key: BOO-1146
>                 URL: http://jira.codehaus.org/browse/BOO-1146
>             Project: Boo
>          Issue Type: New Feature
>          Components: Compiler
>    Affects Versions: 0.9
>            Reporter: Cedric Vivier
>            Assignee: Cedric Vivier
>             Fix For: 0.9.1
>
>
> Current macro macro: syntax is a little unfriendly when it comes to handling arguments, and also lead to a lot of code duplication wrt argument checks.
> It would be nice if we could define macro arguments directly through macro 'macro' that would do the work for us.
> We could write this:
> {code}
> macro printTimes(text as string, count as int):
> for i in range(0, count):
> yield [| print $text |]
> printTimes "cool", 3
> {code}
> Instead of this:
> {code}
> macro printTimes:
> if printTimes.Arguments.Count != 2:
> raise "Usage: printTimes <text>, <count>"
> if not printTimes.Arguments[0] isa StringLiteralExpression:
> raise "Usage: printTimes <text>, <count> : `text` must be string literal"
> if not printTimes.Arguments[1] isa IntegerLiteralExpression:
> raise "Usage: printTimes <text>, <count> : `text` must be int literal"
> text = cast(StringLiteralExpression, printTimes.Arguments[0]).Value
> count = cast(IntegerLiteralExpression, printTimes.Arguments[1]).Value
> for i in range(0, count):
> yield [| print $text |]
> {code}
> Also we could write this:
> {code}
> macro when(condition):
> yield [|
> if $condition:
> $when.Body
> |]
> {code}
> Instead of this:
> {code}
> macro when:
> if when.Arguments.Count != 1:
> raise "Usage: when <expression>"
> yield [|
> if $(when.Arguments[0]):
> $when.Body
> |]
> {code}

--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://jira.codehaus.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

       

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



[jira] Issue Comment Edited: (BOO-1146) Macro definition arguments

by JIRA jira@codehaus.org :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


    [ http://jira.codehaus.org/browse/BOO-1146?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=163667#action_163667 ]

Cedric Vivier edited comment on BOO-1146 at 2/3/09 3:28 AM:
------------------------------------------------------------

Initial support (handles testcase macro-arguments-1 above) landed in rev. 3231+3232

Next steps:
- `body` argument to match against macro.Body
- enumerable/arrray argument types
- macro overloads


      was (Author: cedricv):
    Initial support (handles testcase macro-arguments-1 above) landed in rev. 3229+3230

Next steps:
- `body` argument to match against macro.Body
- enumerable/arrray argument types
- macro overloads

 

> Macro definition arguments
> --------------------------
>
>                 Key: BOO-1146
>                 URL: http://jira.codehaus.org/browse/BOO-1146
>             Project: Boo
>          Issue Type: New Feature
>          Components: Compiler
>    Affects Versions: 0.9
>            Reporter: Cedric Vivier
>            Assignee: Cedric Vivier
>             Fix For: 0.9.1
>
>
> Current macro macro: syntax is a little unfriendly when it comes to handling arguments, and also lead to a lot of code duplication wrt argument checks.
> It would be nice if we could define macro arguments directly through macro 'macro' that would do the work for us.
> We could write this:
> {code}
> macro printTimes(text as string, count as int):
> for i in range(0, count):
> yield [| print $text |]
> printTimes "cool", 3
> {code}
> Instead of this:
> {code}
> macro printTimes:
> if printTimes.Arguments.Count != 2:
> raise "Usage: printTimes <text>, <count>"
> if not printTimes.Arguments[0] isa StringLiteralExpression:
> raise "Usage: printTimes <text>, <count> : `text` must be string literal"
> if not printTimes.Arguments[1] isa IntegerLiteralExpression:
> raise "Usage: printTimes <text>, <count> : `text` must be int literal"
> text = cast(StringLiteralExpression, printTimes.Arguments[0]).Value
> count = cast(IntegerLiteralExpression, printTimes.Arguments[1]).Value
> for i in range(0, count):
> yield [| print $text |]
> {code}
> Also we could write this:
> {code}
> macro when(condition):
> yield [|
> if $condition:
> $when.Body
> |]
> {code}
> Instead of this:
> {code}
> macro when:
> if when.Arguments.Count != 1:
> raise "Usage: when <expression>"
> yield [|
> if $(when.Arguments[0]):
> $when.Body
> |]
> {code}

--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://jira.codehaus.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

       

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



[jira] Updated: (BOO-1146) Macro definition arguments

by JIRA jira@codehaus.org :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


     [ http://jira.codehaus.org/browse/BOO-1146?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Cedric Vivier updated BOO-1146:
-------------------------------

    Description:
Current macro macro: syntax is a little unfriendly when it comes to handling and checking arguments.
Either you manually do a lot of manual checks and casting, either you use pattern matching to match arguments, but it is somewhat non-wrist-friendly to do it for simple patterns).

Macro definitions now support arguments definition in a wrist-friendly and intuitive way, including handling of variable number of (optional) arguments.
To match a variable number of arguments use T* (enumerable) notation (e.g 'arg as string*' for a variable number of string arguments).
To match argument type against macro's body, just name the argument `body` (e.g 'body as MethodInvocationExpression*' for allowing only method invocation expressions within the body).


Testcase (and documentation ;) ):
{code}
"""
the sum of those 6 numbers is 108
foofoo
barbar
invocation #1 of 2
invocation #2 of 2
Line 'How do you bou?' contains unknown word 'bou'. Did you mean 'boo'?
"""
import System
import Boo.Lang.Compiler.Ast
import Boo.Lang.PatternMatching

macro sum(numbers as int*):
        s = 0
        for n in numbers:
                s += n
        yield [| print "the sum of those ${$(numbers.Count)} numbers is ${$s}" |]

macro repeatLines(repeatCount as int, lines as string*):
        for line in lines:
                yield [| print $line * $repeatCount |]

macro invokeWithCount(body as MethodInvocationExpression*):
        for invocation in body:
                invocation.Arguments.Add([| $(body.Count) |])
                yield invocation

macro spellCheck(lang as string, body as string*):
        raise "Unknown language `${lang}`" if lang != "en-EN"
        for line in body:
                if line.Contains("bou"):
                        yield [| print "line '${$line}' contains unknown word 'bou'. Did you mean 'boo'?" |]


sum 4, 8, 15, 16, 23, 42

repeatLines 2, "foo", "bar"

invokeWithCount:
        Console.WriteLine("invocation #1 of {0}")
        Console.WriteLine("invocation #2 of {0}")

spellCheck "en-EN":
        "Hello boo!"
        "How do you bou?"
{code}



  was:
Current macro macro: syntax is a little unfriendly when it comes to handling and checking arguments.
Either you manually do a lot of manual checks and casting, either you use pattern matching to match arguments, but it is somewhat non-wrist-friendly to do it for simple patterns).

Macro definitions now support arguments definition in a wrist-friendly and intuitive way, including handling of variable number of (optional) arguments.
To match a variable number of arguments use T* (enumerable) notation (e.g 'arg as string*' for a variable number of string arguments).
To match argument type against macro.Body you just need to call the argument `body` (e.g 'body as MethodInvocationExpression*' for allowing only method invocation expressions inside the macro body).


Testcase (and documentation ;) ):
{code}
"""
the sum of those 6 numbers is 108
foofoo
barbar
invocation #1 of 2
invocation #2 of 2
Line 'How do you bou?' contains unknown word 'bou'. Did you mean 'boo'?
"""
import System
import Boo.Lang.Compiler.Ast
import Boo.Lang.PatternMatching

macro sum(numbers as int*):
        s = 0
        for n in numbers:
                s += n
        yield [| print "the sum of those ${$(numbers.Count)} numbers is ${$s}" |]

macro repeatLines(repeatCount as int, lines as string*):
        for line in lines:
                yield [| print $line * $repeatCount |]

macro invokeWithCount(body as MethodInvocationExpression*):
        for invocation in body:
                invocation.Arguments.Add([| $(body.Count) |])
                yield invocation

macro spellCheck(lang as string, body as string*):
        raise "Unknown language `${lang}`" if lang != "en-EN"
        for line in body:
                if line.Contains("bou"):
                        yield [| print "line '${$line}' contains unknown word 'bou'. Did you mean 'boo'?" |]


sum 4, 8, 15, 16, 23, 42

repeatLines 2, "foo", "bar"

invokeWithCount:
        Console.WriteLine("invocation #1 of {0}")
        Console.WriteLine("invocation #2 of {0}")

spellCheck "en-EN":
        "Hello boo!"
        "How do you bou?"
{code}




> Macro definition arguments
> --------------------------
>
>                 Key: BOO-1146
>                 URL: http://jira.codehaus.org/browse/BOO-1146
>             Project: Boo
>          Issue Type: New Feature
>          Components: Compiler
>    Affects Versions: 0.9
>            Reporter: Cedric Vivier
>            Assignee: Cedric Vivier
>             Fix For: 0.9.1
>
>
> Current macro macro: syntax is a little unfriendly when it comes to handling and checking arguments.
> Either you manually do a lot of manual checks and casting, either you use pattern matching to match arguments, but it is somewhat non-wrist-friendly to do it for simple patterns).
> Macro definitions now support arguments definition in a wrist-friendly and intuitive way, including handling of variable number of (optional) arguments.
> To match a variable number of arguments use T* (enumerable) notation (e.g 'arg as string*' for a variable number of string arguments).
> To match argument type against macro's body, just name the argument `body` (e.g 'body as MethodInvocationExpression*' for allowing only method invocation expressions within the body).
> Testcase (and documentation ;) ):
> {code}
> """
> the sum of those 6 numbers is 108
> foofoo
> barbar
> invocation #1 of 2
> invocation #2 of 2
> Line 'How do you bou?' contains unknown word 'bou'. Did you mean 'boo'?
> """
> import System
> import Boo.Lang.Compiler.Ast
> import Boo.Lang.PatternMatching
> macro sum(numbers as int*):
> s = 0
> for n in numbers:
> s += n
> yield [| print "the sum of those ${$(numbers.Count)} numbers is ${$s}" |]
> macro repeatLines(repeatCount as int, lines as string*):
> for line in lines:
> yield [| print $line * $repeatCount |]
> macro invokeWithCount(body as MethodInvocationExpression*):
> for invocation in body:
> invocation.Arguments.Add([| $(body.Count) |])
> yield invocation
> macro spellCheck(lang as string, body as string*):
> raise "Unknown language `${lang}`" if lang != "en-EN"
> for line in body:
> if line.Contains("bou"):
> yield [| print "line '${$line}' contains unknown word 'bou'. Did you mean 'boo'?" |]
> sum 4, 8, 15, 16, 23, 42
> repeatLines 2, "foo", "bar"
> invokeWithCount:
> Console.WriteLine("invocation #1 of {0}")
> Console.WriteLine("invocation #2 of {0}")
> spellCheck "en-EN":
> "Hello boo!"
> "How do you bou?"
> {code}

--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://jira.codehaus.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

       

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



[jira] Updated: (BOO-1146) Macro definition arguments

by JIRA jira@codehaus.org :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


     [ http://jira.codehaus.org/browse/BOO-1146?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Cedric Vivier updated BOO-1146:
-------------------------------

    Description:
Current macro macro: syntax is a little unfriendly when it comes to handling and checking arguments.
Either you manually do a lot of manual checks and casting, either you use pattern matching to match arguments, but it is somewhat non-wrist-friendly to do it for simple patterns).

Macro definitions now support arguments definition in a wrist-friendly and intuitive way, including handling of variable number of (optional) arguments.
To match a variable number of arguments use T* (enumerable) notation (e.g 'arg as string*' for a variable number of string arguments).
To match argument type against macro.Body you just need to call the argument `body` (e.g 'body as MethodInvocationExpression*' for allowing only method invocation expressions inside the macro body).


Testcase (and documentation ;) ):
{code}
"""
the sum of those 6 numbers is 108
foofoo
barbar
invocation #1 of 2
invocation #2 of 2
Line 'How do you bou?' contains unknown word 'bou'. Did you mean 'boo'?
"""
import System
import Boo.Lang.Compiler.Ast
import Boo.Lang.PatternMatching

macro sum(numbers as int*):
        s = 0
        for n in numbers:
                s += n
        yield [| print "the sum of those ${$(numbers.Count)} numbers is ${$s}" |]

macro repeatLines(repeatCount as int, lines as string*):
        for line in lines:
                yield [| print $line * $repeatCount |]

macro invokeWithCount(body as MethodInvocationExpression*):
        for invocation in body:
                invocation.Arguments.Add([| $(body.Count) |])
                yield invocation

macro spellCheck(lang as string, body as string*):
        raise "Unknown language `${lang}`" if lang != "en-EN"
        for line in body:
                if line.Contains("bou"):
                        yield [| print "line '${$line}' contains unknown word 'bou'. Did you mean 'boo'?" |]


sum 4, 8, 15, 16, 23, 42

repeatLines 2, "foo", "bar"

invokeWithCount:
        Console.WriteLine("invocation #1 of {0}")
        Console.WriteLine("invocation #2 of {0}")

spellCheck "en-EN":
        "Hello boo!"
        "How do you bou?"
{code}



  was:
Current macro macro: syntax is a little unfriendly when it comes to handling arguments, and also lead to a lot of code duplication wrt argument checks.
It would be nice if we could define macro arguments directly through macro 'macro' that would do the work for us.

We could write this:

{code}
macro printTimes(text as string, count as int):
        for i in range(0, count):
                yield [| print $text |]

printTimes "cool", 3
{code}

Instead of this:

{code}
macro printTimes:
        if printTimes.Arguments.Count != 2:
                raise "Usage: printTimes <text>, <count>"
        if not printTimes.Arguments[0] isa StringLiteralExpression:
                raise "Usage: printTimes <text>, <count> : `text` must be string literal"
        if not printTimes.Arguments[1] isa IntegerLiteralExpression:
                raise "Usage: printTimes <text>, <count> : `text` must be int literal"

        text = cast(StringLiteralExpression, printTimes.Arguments[0]).Value
        count = cast(IntegerLiteralExpression, printTimes.Arguments[1]).Value
        for i in range(0, count):
                yield [| print $text |]
{code}


Also we could write this:

{code}
macro when(condition):
        yield [|
                if $condition:
                        $when.Body
        |]
{code}

Instead of this:

{code}
macro when:
        if when.Arguments.Count != 1:
                raise "Usage: when <expression>"
        yield [|
                if $(when.Arguments[0]):
                        $when.Body
        |]
{code}



> Macro definition arguments
> --------------------------
>
>                 Key: BOO-1146
>                 URL: http://jira.codehaus.org/browse/BOO-1146
>             Project: Boo
>          Issue Type: New Feature
>          Components: Compiler
>    Affects Versions: 0.9
>            Reporter: Cedric Vivier
>            Assignee: Cedric Vivier
>             Fix For: 0.9.1
>
>
> Current macro macro: syntax is a little unfriendly when it comes to handling and checking arguments.
> Either you manually do a lot of manual checks and casting, either you use pattern matching to match arguments, but it is somewhat non-wrist-friendly to do it for simple patterns).
> Macro definitions now support arguments definition in a wrist-friendly and intuitive way, including handling of variable number of (optional) arguments.
> To match a variable number of arguments use T* (enumerable) notation (e.g 'arg as string*' for a variable number of string arguments).
> To match argument type against macro.Body you just need to call the argument `body` (e.g 'body as MethodInvocationExpression*' for allowing only method invocation expressions inside the macro body).
> Testcase (and documentation ;) ):
> {code}
> """
> the sum of those 6 numbers is 108
> foofoo
> barbar
> invocation #1 of 2
> invocation #2 of 2
> Line 'How do you bou?' contains unknown word 'bou'. Did you mean 'boo'?
> """
> import System
> import Boo.Lang.Compiler.Ast
> import Boo.Lang.PatternMatching
> macro sum(numbers as int*):
> s = 0
> for n in numbers:
> s += n
> yield [| print "the sum of those ${$(numbers.Count)} numbers is ${$s}" |]
> macro repeatLines(repeatCount as int, lines as string*):
> for line in lines:
> yield [| print $line * $repeatCount |]
> macro invokeWithCount(body as MethodInvocationExpression*):
> for invocation in body:
> invocation.Arguments.Add([| $(body.Count) |])
> yield invocation
> macro spellCheck(lang as string, body as string*):
> raise "Unknown language `${lang}`" if lang != "en-EN"
> for line in body:
> if line.Contains("bou"):
> yield [| print "line '${$line}' contains unknown word 'bou'. Did you mean 'boo'?" |]
> sum 4, 8, 15, 16, 23, 42
> repeatLines 2, "foo", "bar"
> invokeWithCount:
> Console.WriteLine("invocation #1 of {0}")
> Console.WriteLine("invocation #2 of {0}")
> spellCheck "en-EN":
> "Hello boo!"
> "How do you bou?"
> {code}

--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://jira.codehaus.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

       

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



[jira] Resolved: (BOO-1146) Macro definition arguments

by JIRA jira@codehaus.org :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


     [ http://jira.codehaus.org/browse/BOO-1146?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Cedric Vivier resolved BOO-1146.
--------------------------------

    Resolution: Fixed

Fully landed in rev. 3244
Forked macro overloading to BOO-1156


> Macro definition arguments
> --------------------------
>
>                 Key: BOO-1146
>                 URL: http://jira.codehaus.org/browse/BOO-1146
>             Project: Boo
>          Issue Type: New Feature
>          Components: Compiler
>    Affects Versions: 0.9
>            Reporter: Cedric Vivier
>            Assignee: Cedric Vivier
>             Fix For: 0.9.1
>
>
> Current macro macro: syntax is a little unfriendly when it comes to handling and checking arguments.
> Either you manually do a lot of manual checks and casting, either you use pattern matching to match arguments, but it is somewhat non-wrist-friendly to do it for simple patterns).
> Macro definitions now support arguments definition in a wrist-friendly and intuitive way, including handling of variable number of (optional) arguments.
> To match a variable number of arguments use T* (enumerable) notation (e.g 'arg as string*' for a variable number of string arguments).
> To match argument type against macro's body, just name the argument `body` (e.g 'body as MethodInvocationExpression*' for allowing only method invocation expressions within the body).
> Testcase (and documentation ;) ):
> {code}
> """
> the sum of those 6 numbers is 108
> foofoo
> barbar
> invocation #1 of 2
> invocation #2 of 2
> Line 'How do you bou?' contains unknown word 'bou'. Did you mean 'boo'?
> """
> import System
> import Boo.Lang.Compiler.Ast
> import Boo.Lang.PatternMatching
> macro sum(numbers as int*):
> s = 0
> for n in numbers:
> s += n
> yield [| print "the sum of those ${$(numbers.Count)} numbers is ${$s}" |]
> macro repeatLines(repeatCount as int, lines as string*):
> for line in lines:
> yield [| print $line * $repeatCount |]
> macro invokeWithCount(body as MethodInvocationExpression*):
> for invocation in body:
> invocation.Arguments.Add([| $(body.Count) |])
> yield invocation
> macro spellCheck(lang as string, body as string*):
> raise "Unknown language `${lang}`" if lang != "en-EN"
> for line in body:
> if line.Contains("bou"):
> yield [| print "line '${$line}' contains unknown word 'bou'. Did you mean 'boo'?" |]
> sum 4, 8, 15, 16, 23, 42
> repeatLines 2, "foo", "bar"
> invokeWithCount:
> Console.WriteLine("invocation #1 of {0}")
> Console.WriteLine("invocation #2 of {0}")
> spellCheck "en-EN":
> "Hello boo!"
> "How do you bou?"
> {code}

--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://jira.codehaus.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

       

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



[jira] Updated: (BOO-1146) Macro named (and typed) arguments

by JIRA jira@codehaus.org :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


     [ http://jira.codehaus.org/browse/BOO-1146?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Cedric Vivier updated BOO-1146:
-------------------------------

    Summary: Macro named (and typed) arguments  (was: Macro definition arguments)

> Macro named (and typed) arguments
> ---------------------------------
>
>                 Key: BOO-1146
>                 URL: http://jira.codehaus.org/browse/BOO-1146
>             Project: Boo
>          Issue Type: New Feature
>          Components: Compiler
>    Affects Versions: 0.9
>            Reporter: Cedric Vivier
>            Assignee: Cedric Vivier
>             Fix For: 0.9.1
>
>
> Current macro macro: syntax is a little unfriendly when it comes to handling and checking arguments.
> Either you manually do a lot of manual checks and casting, either you use pattern matching to match arguments, but it is somewhat non-wrist-friendly to do it for simple patterns).
> Macro definitions now support arguments definition in a wrist-friendly and intuitive way, including handling of variable number of (optional) arguments.
> To match a variable number of arguments use T* (enumerable) notation (e.g 'arg as string*' for a variable number of string arguments).
> To match argument type against macro's body, just name the argument `body` (e.g 'body as MethodInvocationExpression*' for allowing only method invocation expressions within the body).
> Testcase (and documentation ;) ):
> {code}
> """
> the sum of those 6 numbers is 108
> foofoo
> barbar
> invocation #1 of 2
> invocation #2 of 2
> Line 'How do you bou?' contains unknown word 'bou'. Did you mean 'boo'?
> """
> import System
> import Boo.Lang.Compiler.Ast
> import Boo.Lang.PatternMatching
> macro sum(numbers as int*):
> s = 0
> for n in numbers:
> s += n
> yield [| print "the sum of those ${$(numbers.Count)} numbers is ${$s}" |]
> macro repeatLines(repeatCount as int, lines as string*):
> for line in lines:
> yield [| print $line * $repeatCount |]
> macro invokeWithCount(body as MethodInvocationExpression*):
> for invocation in body:
> invocation.Arguments.Add([| $(body.Count) |])
> yield invocation
> macro spellCheck(lang as string, body as string*):
> raise "Unknown language `${lang}`" if lang != "en-EN"
> for line in body:
> if line.Contains("bou"):
> yield [| print "line '${$line}' contains unknown word 'bou'. Did you mean 'boo'?" |]
> sum 4, 8, 15, 16, 23, 42
> repeatLines 2, "foo", "bar"
> invokeWithCount:
> Console.WriteLine("invocation #1 of {0}")
> Console.WriteLine("invocation #2 of {0}")
> spellCheck "en-EN":
> "Hello boo!"
> "How do you bou?"
> {code}

--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://jira.codehaus.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

       

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



[jira] Closed: (BOO-1146) Macro named (and typed) arguments

by JIRA jira@codehaus.org :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


     [ http://jira.codehaus.org/browse/BOO-1146?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Rodrigo B. de Oliveira closed BOO-1146.
---------------------------------------


> Macro named (and typed) arguments
> ---------------------------------
>
>                 Key: BOO-1146
>                 URL: http://jira.codehaus.org/browse/BOO-1146
>             Project: Boo
>          Issue Type: New Feature
>          Components: Compiler
>    Affects Versions: 0.9
>            Reporter: Cedric Vivier
>            Assignee: Cedric Vivier
>             Fix For: 0.9.1
>
>
> Current macro macro: syntax is a little unfriendly when it comes to handling and checking arguments.
> Either you manually do a lot of manual checks and casting, either you use pattern matching to match arguments, but it is somewhat non-wrist-friendly to do it for simple patterns).
> Macro definitions now support arguments definition in a wrist-friendly and intuitive way, including handling of variable number of (optional) arguments.
> To match a variable number of arguments use T* (enumerable) notation (e.g 'arg as string*' for a variable number of string arguments).
> To match argument type against macro's body, just name the argument `body` (e.g 'body as MethodInvocationExpression*' for allowing only method invocation expressions within the body).
> Testcase (and documentation ;) ):
> {code}
> """
> the sum of those 6 numbers is 108
> foofoo
> barbar
> invocation #1 of 2
> invocation #2 of 2
> Line 'How do you bou?' contains unknown word 'bou'. Did you mean 'boo'?
> """
> import System
> import Boo.Lang.Compiler.Ast
> import Boo.Lang.PatternMatching
> macro sum(numbers as int*):
> s = 0
> for n in numbers:
> s += n
> yield [| print "the sum of those ${$(numbers.Count)} numbers is ${$s}" |]
> macro repeatLines(repeatCount as int, lines as string*):
> for line in lines:
> yield [| print $line * $repeatCount |]
> macro invokeWithCount(body as MethodInvocationExpression*):
> for invocation in body:
> invocation.Arguments.Add([| $(body.Count) |])
> yield invocation
> macro spellCheck(lang as string, body as string*):
> raise "Unknown language `${lang}`" if lang != "en-EN"
> for line in body:
> if line.Contains("bou"):
> yield [| print "line '${$line}' contains unknown word 'bou'. Did you mean 'boo'?" |]
> sum 4, 8, 15, 16, 23, 42
> repeatLines 2, "foo", "bar"
> invokeWithCount:
> Console.WriteLine("invocation #1 of {0}")
> Console.WriteLine("invocation #2 of {0}")
> spellCheck "en-EN":
> "Hello boo!"
> "How do you bou?"
> {code}

--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://jira.codehaus.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

       

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email