tomhrr / dale

Lisp-flavoured C
BSD 3-Clause "New" or "Revised" License
1.03k stars 48 forks source link

Simplify simple macros #127

Open porky11 opened 8 years ago

porky11 commented 8 years ago

instead of (qq a (uq b) (uq c)) you would rather like to write (make-macro (a b c)) and this could simply be done with mfor

(qq mfor b ((uq b))
  (mfor c ((uq c))
    (a b c)))

this is useful if there are only a few variables, that would be unquotet, but are often used inside the macro, like in some macro I used, where I don't want to write (uq …) for each variable (see end of this comment)

but when there are many variables, this will get complicated, so something like (make-macro list-of-variables ...body) would be more clear in such cases, where list-of-variables would be similar to a list in let

  ;;part of my macro
    (qq mfor T (uq types)
      (mfor N (uq nums)

        (implement BasicMath T)

        (instantiate Array T N)
        (instantiate basic-math (Array T N))

        (def dot (fn intern T ((x (Array T N)) (y (Array T N)))
          (+ (* (@$ x 0) (@$ y 0)) (* (@$ x 1) (@$ y 1)))))

        (instantiate Array T 3)

        (instantiate Ball T N)
        (instantiate collide (Ball T N))
        (def-ptr-macro2 collide intern (Ball T N))
    …))