Arc Forumnew | comments | leaders | submitlogin
3 points by aw 5345 days ago | link | parent

Please show an example of using macro-alias, if you had a working version :)

I expect you want

  ,',b
Imagine the variable "b" contains the symbol "foo". You want to insert (the first comma) the symbol "foo" (,foo) but that would treat foo like a variable, so you have to quote it (,'foo) to get a literal "foo".

Now you want to substitute the value of b for foo, so replace foo with (,b).

  ,'foo
  foo => ,b
  ,',b
Why one quote instead of two?

  ,','b
That's because you don't want a literal "b", you want the value the variable "b" contains.

Why one quote instead of zero?

  ,,b
because you don't want the value of the variable "foo" when b contains the symbol foo, you want a literal foo.

Why do you have to use ,' at all? After all

  `(one two three)
inserts literal symbols without any messing around. But now you have no way to evaluate anything.

Imagine that symbols didn't "auto quote" themselves in a quasiquotation expression. That is, suppose that `(one two three) was an error. Just wasn't implemented. So you had to write

  `(,'one ,'two ,'there)
now it's easier to see where ,',b comes from.

Wow, this is pretty cool. I've never had a way to explain ,', before ^_^



1 point by akkartik 5345 days ago | link

Thanks, that was exactly what I wanted.

I could swear I tried ,', .. :/

I successfully applied your thinking to make args a gensym:

  (mac macro-alias(a b)
    (w/uniq args
      `(mac ,a ,args
         `(,',b ,@,args))))
This works like alias at http://arclanguage.org/item?id=13097 for macros. (It would also works on functions, but macro-aliases of functions are not first-class functions.)

-----

1 point by akkartik 5344 days ago | link

My lesson from this experience: quote and unquote are not exact opposites.

  > (define a 3)
  > `(list ',a)
  '(list '3)
  > `(list ,'a)
  '(list a)

-----

1 point by aw 5344 days ago | link

oops, typo

s/if you had a working version/as if you had a working version/

-----