Arc Forumnew | comments | leaders | submitlogin
2 points by Pauan 4441 days ago | link | parent

This reminds me of Shen macros[1], which are strictly more powerful than Arc-style macros:

  ; Arc
  (mac and args
    (if args
        (if (cdr args)
            `(if ,(car args) (and ,@(cdr args)))
            (car args))
        't))

  ; Shen
  (defmacro andmacro
    [and]       -> true
    [and X]     -> X
    [and X | R] -> [if X [and | R]])
Because Shen macros operate on the entire code structure rather than the arguments of the macro, you can do silly stuff like replace the number 2 with the number 2.5:

  (defmacro twomacro
    2 -> 2.5)
And now (+ 2 2) returns 5.

---

* [1]: http://shenlanguage.org/learn-shen/macros.html



3 points by akkartik 4441 days ago | link

I thought there was a connection with pattern matching.

But why does Shen even bother naming these macros? What operations can you perform on andmacro?

-----

2 points by Pauan 4440 days ago | link

In Shen, macros are stored in a global list. I'm guessing you name them so that you can update/remove them later or something. I guess it can also serve as documentation? I dunno. I also thought it was weird that they were named.

-----