Now, another question:
I'm playing a little with macros, and I'm building a macro that builds
a function using the list data type. Here it is:
(define-macro m2
(lambda ()
(list 'define 'm2
(list 'automaton 'init
#\[ 'init #\:
(list 'c '-> 'more)#\]
#\[ 'more #\:
(list 'a '-> 'more)
(list 'd '-> 'more)
(list 'r '-> 'end)#\]
#\[ 'end #\: 'accept
#\]
))))
This macro uses the 'automation' template, which is not the issue
here. The fact is that I cannot (don't know how to) build a function
that uses these square brackets. The next code, within the macro,
(display
(list 'define 'm2
(list 'automaton 'init
#\[ 'init #\:
(list 'c '-> 'more)#\]
#\[ 'more #\:
(list 'a '-> 'more)
(list 'd '-> 'more)
(list 'r '-> 'end)#\]
#\[ 'end #\: 'accept
#\]
)))
gives the following result:
(define m2 (automaton init [ init : (c -> more) ] [ more : (a -> more)
(d -> more) (r -> end) ] [ end : accept ]))
which is what I'm looking for.
But when I run the macro, the #\ and " " operators doesn't work.
So, I get as result this:
automaton: bad syntax in: (automaton init #\[ init #\: (c -> more) #\]
#\[ more #\: (a -> more) (d -> more) (r -> end) #\] #\[ end #\: accept
#\])
which is wrong.
Any ideas?
Thanks!
Virgilio
I forgot to say that I'm using the Pretty Big implementation.
> Now, another question:
> I'm playing a little with macros, and I'm building a macro that builds
> a function using the list data type. Here it is:
>
> (define-macro m2
> (lambda ()
> (list 'define 'm2
> (list 'automaton 'init
> #\[ 'init #\:
> (list 'c '-> 'more)#\]
> #\[ 'more #\:
> (list 'a '-> 'more)
> (list 'd '-> 'more)
> (list 'r '-> 'end)#\]
> #\[ 'end #\: 'accept
> #\]
> ))))
So, this is a macro called m2 that defines a procedure also called m2?
> This macro uses the 'automation' template, which is not the issue
> here. The fact is that I cannot (don't know how to) build a function
> that uses these square brackets.
Square brackets and parenthesis are exactly the same thing. You are
using the characters #\[ and #\] in the code above, which does not
construct lists.
> The next code, within the macro,
>
> (display
> (list 'define 'm2
> (list 'automaton 'init
> #\[ 'init #\:
> (list 'c '-> 'more)#\]
> #\[ 'more #\:
> (list 'a '-> 'more)
> (list 'd '-> 'more)
> (list 'r '-> 'end)#\]
> #\[ 'end #\: 'accept
> #\]
> )))
>
> gives the following result:
>
> (define m2 (automaton init [ init : (c -> more) ] [ more : (a -> more)
> (d -> more) (r -> end) ] [ end : accept ]))
Try using write instead of display.
How about we take it from the start? Every macro has an input form.
How do you want to *use* your macro? What should it look like in the
code?
Thank you. Here are more informations:
- My goal is to create a function at run-time.
The function looks like this:
(define afd
(automaton init (init : (c -> q1)) (q1 : (a -> q1) (d -> q1) (r ->
q2)) (q2 : accept)))
- I have one list, called _lstFuncaoMacro, that contains the procedure
above. Can I run a macro to make the function accessible?
> Thank you. Here are more informations:
> - My goal is to create a function at run-time.
Macros do not create functions at run-time, they work at compile time.
Do you mean run-time as in "when the program is run" as opposed to
typing it yourself?
> The function looks like this:
> (define afd
> (automaton init (init : (c -> q1)) (q1 : (a -> q1) (d -> q1) (r ->
> q2)) (q2 : accept)))
That's a definition of a variable called afd. I presume you want to
write the automaton macro, right? What should the result of
(automaton init (init: ---) ---)
be? An automaton macro transforms that code into something else,
possibly a lambda expression. Can you say what the transformed code
of the (automaton ---) form should look like? Once you know what it
*should* look like, it will be easy to write the macro transformer.
Aziz,,,