Arc Forumnew | comments | leaders | submitlogin
7 points by Darmani 6125 days ago | link | parent

  (let olddef def
    (mac def (name args . body)
      (if (acons name)
        `(def= ,(cadr name) ,args ,@body)
        `(,olddef ,name ,args ,@body))))
Hope that fits what you're looking for.

(I also hope that works -- I'm not at home and can't test it.)



3 points by eds 6124 days ago | link

It almost works... but unfortunately because we don't yet have first class macros it fails with:

  Error: "Bad object in expression #3(tagged mac #<procedure>)"

-----

2 points by absz 6124 days ago | link

Try removing the comma in front of olddef; it should work then.

-----

4 points by Darmani 6124 days ago | link

Unfortunately, that won't work because the form is being returned to a place outside the closure where olddef was defined; when eval is given the form containing olddef, it will not recognize it.

Here's a better definition:

  (let olddef def
    (mac def (name args . body)
      (if (acons name)
        `(def= ,(cadr name) ,args ,@body)
        (apply (rep olddef) (cons name (cons args body))))))

-----

2 points by absz 6124 days ago | link

Shouldn't that be (mac def ...)?

Anyway, nice work, but damn do we need 1st-class macros.

-----

3 points by Darmani 6124 days ago | link

Oops -- thank you. Fixed.

-----