Arc Forumnew | comments | leaders | submitlogin
2 points by akkartik 4848 days ago | link | parent

(Warning, uses syntax from OP)

Ah, I just ran into a limitation of defmacro! -- it can't 'see inside' when the macro is computed by a function. For example:

  (defun foodef(x)
    `(let ((,g!x ,x))
       (+ 1 ,g!x)))

  (defmacro! foomac(x)
    (foodef x))
The solution I came up with is to create a defun! to generate such functions, and then have def and mac generate defun! and defmacro! https://github.com/akkartik/wart/commit/f4e4859ea77ff02691c3... (Warning: uses different syntax than OP)

I like this idea more and more; I've basically gotten rid of w/uniq entirely in wart.



4 points by rocketnia 4847 days ago | link

Have you considered just making 'g an anaphoric variable of 'mac that holds a memoized function that generates gensyms, so that g!x is (g 'x) as usual? ^_^

Then you can explicitly pass 'g to 'foodef. If that isn't enough, 'g could instead be a global function whose behavior changes during the dynamic scope of each macro expansion. Hmm, then you can't have more than one 'g at once, but when would you have that anyway? XD Something like Lathe's namespaces might use multiple instances of 'g, but those occasional cases can fend for themselves.

-----

1 point by akkartik 4847 days ago | link

Ooh, interesting idea.

-----