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

The couple of times I've tried it I find I get tangled up in how I want to interleave macroexpansion vs evaluation. I'm sure I don't know all the tools available to me (', / ,, / ,', / ,,@ / ...)

I should try to come up with a simple example. Perhaps the canonical one is Peter Norvig's once-only that that link refers to (which also says nested backquotes are hard). I believe it's come up multiple times here, e.g. http://www.arclanguage.org/item?id=9918

Hold on, lemme push my latest commit and break wart on github :) Now you can try to make sense of my struggles at https://github.com/akkartik/wart/blob/9bd437782d6c3e862ae388... if you're so moved. (There's a 'Desired' comment halfway down which shows what I'm trying to get, and the testcase is right at the bottom of the file.)

So far nested backquotes are the only thing I've found that remained hard after using unit tests.



2 points by rocketnia 5354 days ago | link

I think your desired behavior is wrong. You'd like the inner body of a once-only definition to be like this:

  `(let* (($x o$x))
     (+ ,$x 1))
But the macro user would write that body as `(+ ,$x 1), with the backquote and everything, and you don't have that backquote in your hypothetical expansion. What you're probably looking for is:

  `(let* (($x o$x))
     ,`(+ ,$x 1))
Or, more accurately:

  `(let* (($x o$x))
     ,(progn `(+ ,$x 1)))  ; listing all the expressions in the body
Sorry, that's all the time I have to look at it right now. XD

Also, this isn't much of a response to the "generally hard" topic (except to prove this example takes more thought than I've given it so far :-p ).

-----

1 point by akkartik 5354 days ago | link

That is extremely helpful, thanks! I think it's awesome that you can read my ugly code so fast.

Update: Now when I look at it again I notice defmacro! also uses the ,(progn ,@body) trick. Thanks again.

-----