Defining syntactic macros in interpreter

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

Defining syntactic macros in interpreter

by Andreas Bednarek :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Hi, is that any possible?

I tried the example from web (0.9.1. release notes) with booish and
this is the result

CONSOLE
Welcome to booish, an interactive interpreter for the boo programming
language.
Running boo 0.9.2.3383 on CLR 2.0.50727.3603.

Enter boo code in the prompt below (or type /help).
>>>macro repeatLines(repeatCount as int, lines as string*):
...        for line in lines:
...                for i in range(repeatCount):
...                        print line
...
----^
ERROR: Unknown identifier: 'match'.
----^
ERROR: Unknown identifier: 'case'.
----------------------^
ERROR: Unknown identifier: 'repeatCount'.
----^
ERROR: Unknown identifier: '_'.
----^
ERROR: Target of explode expression must be an array.
-----------------------------------^
ERROR: Unknown identifier: 'repeatCount'.
----^
ERROR: Unknown identifier: 'otherwise'.
>>>
ENDCONSOLE



Similar trouble, when passing the macro code to
InteractiveInterpreter2.Eval() (newlines and tabs are used in the
passed string to indent the same way as above)

input12(1,1): BCE0005: Boo.Lang.Compiler.CompilerError: Unknown
identifier: 'macro'.
input12(1,7): BCE0005: Boo.Lang.Compiler.CompilerError: Unknown
identifier: 'repeatLines'.
input12(1,19): BCE0005: Boo.Lang.Compiler.CompilerError: Unknown
identifier: 'repeatCount'.
input12(1,34): BCE0006: Boo.Lang.Compiler.CompilerError: 'int' is a
value type. The 'as' operator can only be used with reference types.
input12(1,39): BCE0005: Boo.Lang.Compiler.CompilerError: Unknown
identifier: 'lines'.
input12(2,17): BCE0005: Boo.Lang.Compiler.CompilerError: Unknown
identifier: 'lines'.
input12(3,24): BCE0005: Boo.Lang.Compiler.CompilerError: Unknown
identifier: 'repeatCount'.

To make the second approach function (using Eval()) would be awesome.

Thanks

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Boo Programming Language" group.
To post to this group, send email to boolang@...
To unsubscribe from this group, send email to boolang+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/boolang?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: Defining syntactic macros in interpreter

by Rodrigo B. de Oliveira :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


On Mon, Nov 2, 2009 at 4:30 AM, andris <andris@...> wrote:
>
> Hi, is that any possible?
>

Yes.

> I tried the example from web (0.9.1. release notes) with booish and
> this is the result
>
> CONSOLE
> Welcome to booish, an interactive interpreter for the boo programming
> language.
> Running boo 0.9.2.3383 on CLR 2.0.50727.3603.
>
> Enter boo code in the prompt below (or type /help).
>>>>macro repeatLines(repeatCount as int, lines as string*):
> ...        for line in lines:
> ...                for i in range(repeatCount):
> ...                        print line
> ...
> ----^
> ERROR: Unknown identifier: 'match'.
> ----^
> ERROR: Unknown identifier: 'case'.
> ----------------------^

Yeah, that's annoying. You have to "import Boo.Lang.PatternMatching"
before defining the macro. We'll fix that for the next release.

Best,
Rodrigo

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Boo Programming Language" group.
To post to this group, send email to boolang@...
To unsubscribe from this group, send email to boolang+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/boolang?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: Defining syntactic macros in interpreter

by Andreas Bednarek :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


>
> Yeah, that's annoying. You have to "import Boo.Lang.PatternMatching"
> before defining the macro. We'll fix that for the next release.
>

Great, that worked for booish.exe.

When using InteractiveInterpreter2.Eval() I still can't define any
macro, the errors are same as mentioned above.

InteractiveInterpreter2 interpreter = new InteractiveInterpreter2();
interpreter.Eval("load(\"Boo.Lang.PatternMatching.dll\")");
interpreter.Eval("import Boo.Lang.PatternMatching");
interpreter.Eval("macro repeatLines(repeatCount as int, lines as
string*):\n" +
                        " for line in lines:\n" +
                        " for i in range(repeatCount):\n" +
                        " print line\n");


is what I do in C#

Could there be something missing yet?

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Boo Programming Language" group.
To post to this group, send email to boolang@...
To unsubscribe from this group, send email to boolang+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/boolang?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: Defining syntactic macros in interpreter

by Andreas Bednarek :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


>When using InteractiveInterpreter2.Eval() I still can't define any
>macro, the errors are same as mentioned above.

That was solved automagically, I have no idea what was wrong, but
after I turned PC on again, it started to work ;)
Sorry, thanks


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Boo Programming Language" group.
To post to this group, send email to boolang@...
To unsubscribe from this group, send email to boolang+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/boolang?hl=en
-~----------~----~----~----~------~----~------~--~---