Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Square brackets issue.

2 views
Skip to first unread message

Virgílio Vettorazzo

unread,
Mar 22, 2008, 4:33:39 PM3/22/08
to
First of all, thank you guys for your great help in my first post in
this group (the question related to libraries).

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

Virgílio Vettorazzo

unread,
Mar 22, 2008, 5:01:52 PM3/22/08
to

I forgot to say that I'm using the Pretty Big implementation.

Abdulaziz Ghuloum

unread,
Mar 22, 2008, 9:47:00 PM3/22/08
to
Virgílio Vettorazzo wrote:

> 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?

Virgílio Vettorazzo

unread,
Mar 23, 2008, 12:46:55 AM3/23/08
to
On Mar 22, 10:47 pm, Abdulaziz Ghuloum <aghul...@cee.ess.indiana.edu>
wrote:

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?

Abdulaziz Ghuloum

unread,
Mar 24, 2008, 12:28:04 AM3/24/08
to
Virgílio Vettorazzo wrote:

> 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,,,

0 new messages