Home > Archive > Dylan > December 2004 > Q: Macro expnasion does not work, what is wrong?
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Q: Macro expnasion does not work, what is wrong?
|
|
| Michael Erdmann 2004-12-11, 8:55 am |
| Hallo,
i am trying to create a macro called frame, which shall allow
the following statement;
define frame test-frame
field color;
field size;
end ;
When i compile the fragment below i get an error:
Inside expansion of ``define frame'' macro.
"ma.dylan", line 33, character 3 through line 35, character 5:
define frame test-frame
^^^^^^^^^^^^^^^^^^^^^^^
through
end ;
^^^^^
Error: Parse error at or before left brace
........
I have some questions about it:
Q.1 I found out that the problem seems to be connected
to the {?fields} variable in make-frame-(....,..).
but i expected the fields rewrite to produce a
result like add-field(#"color"), add-field(#"size")
which would produce an argument list for make-frame
What is wrong?
Q.2 How can i debug such thing. With C i can run the
the preprocessor and check the result of any macro
expansion. Does d2c allow such a thing?
Regard
Michael
-------------------------------------------------------
module: ma
synopsis:
author:
copyright:
define method make-frame( name, #rest args ) => ( )
format-out("Name=%s, args=%=\n", name, args );
end method;
define method add-field( args ) => ( <string> )
format-out("Field=%=\n", args );
args;
end method;
define macro frame-definer
{ define frame ?:name ?fields end } => { make-frame( ?#"name",
{?fields} ) } ;
fields:
{ } => { }
{ ?field; ... } => { ?field, ... }
field:
{ field ?:name } => { add-field({?#"name"}) } ;
end macro ;
define function main(name, arguments)
format-out("Hello, world!\n");
define frame test-frame
field x ;
end ;
exit-application(0);
end function main;
// Invoke our main() function.
main(application-name(), application-arguments());
| |
| Michael Erdmann 2004-12-12, 8:55 pm |
| Michael Erdmann wrote:
> Hallo,
This problem has been solved. But the Q.2 still remains!
>
> i am trying to create a macro called frame, which shall allow
> the following statement;
>
> define frame test-frame
> field color;
> field size;
> end ;
>
> When i compile the fragment below i get an error:
>
> Inside expansion of ``define frame'' macro.
> "ma.dylan", line 33, character 3 through line 35, character 5:
> define frame test-frame
> ^^^^^^^^^^^^^^^^^^^^^^^
> through
> end ;
> ^^^^^
> Error: Parse error at or before left brace
> .......
>
>
> I have some questions about it:
>
> Q.1 I found out that the problem seems to be connected
> to the {?fields} variable in make-frame-(....,..).
> but i expected the fields rewrite to produce a
> result like add-field(#"color"), add-field(#"size")
> which would produce an argument list for make-frame
> What is wrong?
>
> Q.2 How can i debug such thing. With C i can run the
> the preprocessor and check the result of any macro
> expansion. Does d2c allow such a thing?
>
>
> Regard
> Michael
>
>
> -------------------------------------------------------
> module: ma
> synopsis:
> author:
> copyright:
>
>
> define method make-frame( name, #rest args ) => ( )
> format-out("Name=%s, args=%=\n", name, args );
> end method;
>
> define method add-field( args ) => ( <string> )
> format-out("Field=%=\n", args );
> args;
> end method;
>
>
> define macro frame-definer
> { define frame ?:name ?fields end } => { make-frame( ?#"name",
> {?fields} ) } ;
>
> fields:
> { } => { }
> { ?field; ... } => { ?field, ... }
>
> field:
> { field ?:name } => { add-field({?#"name"}) } ;
>
> end macro ;
>
>
> define function main(name, arguments)
> format-out("Hello, world!\n");
>
> define frame test-frame
> field x ;
> end ;
>
> exit-application(0);
> end function main;
>
> // Invoke our main() function.
> main(application-name(), application-arguments());
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
| |
|
| Michael, in Functional Developer you can see macro expansions by using
the Project -> Macroexpand Selection menu item, after compiling your
project. I don't know if d2c has anything equivalent.
-Carl
|
|
|
|
|