Macro Status

1 view
Skip to first unread message

Red Daly

unread,
Mar 24, 2009, 9:51:45 PM3/24/09
to program...@googlegroups.com
I am having trouble defining my own macros.  I have been playing around in nush and looking for examples, but no real luck so far:

% (macro inc! (n) (set ,n (+ ,n 1)))
(macro-0 inc! ((n) (set (quasiquote-eval n) (+ (quasiquote-eval n) 1))))
% (set a 1)
1
% (inc! a)
NuUndefinedSymbol: undefined symbol: n
% (macro nothing (n) 12)
(macro-0 nothing ((n) 12))
% (nothing 3)
NuUndefinedSymbol: undefined symbol: n

are macros implemented as in the documentation?  I might just be missing something.

Thanks!
Red

Tim Burks

unread,
Mar 24, 2009, 11:23:01 PM3/24/09
to program...@googlegroups.com
This will probably do what you want:

% (macro-1 inc! (n) `(set ,n (+ ,n 1)))
(macro-1 inc! (n) ((quasiquote (set (quasiquote-eval n) (+
(quasiquote-eval n) 1)))))
% (set a 1)
1
% (inc! a)
2
% (inc! a)
3

I'm lagging; we should probably go ahead and make "macro-1" the
default for "macro" now. Currently it is "macro-0", the old/original
macro implementation that was much more basic.

Tim

Jeff Buck

unread,
Mar 25, 2009, 10:23:58 PM3/25/09
to Programming Nu
That was my fault. When I wrote up the macro tutorial, I used "macro"
in the code examples where I should have used "macro-1".

Tim, if you like, I can quickly change the tutorial page so the code
reads "macro-1".

Red, sorry for the confusion!

Jeff
Reply all
Reply to author
Forward
0 new messages