Home > Archive > Scheme > March 2008 > Square brackets issue.
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 |
Square brackets issue.
|
|
| Virgílio Vettorazzo 2008-03-22, 7:19 pm |
| 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 2008-03-22, 7:19 pm |
| On Mar 22, 5:33 pm, Virg=EDlio Vettorazzo <virve...@gmail.com> wrote:
> 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
I forgot to say that I'm using the Pretty Big implementation.
| |
| Abdulaziz Ghuloum 2008-03-22, 10:31 pm |
| 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 2008-03-23, 4:55 am |
| On Mar 22, 10:47 pm, Abdulaziz Ghuloum <aghul...@cee.ess.indiana.edu>
wrote:
> Virg=EDlio Vettorazzo wrote:
>
>
> So, this is a macro called m2 that defines a procedure also called m2?
>
>
> Square brackets and parenthesis are exactly the same thing. You are
> using the characters #\[ and #\] in the code above, which does not
> construct lists.
>
>
>
>
>
>
>
> 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?
| |
| Abdulaziz Ghuloum 2008-03-24, 4:40 am |
| 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,,,
|
|
|
|
|