Arc Forumnew | comments | leaders | submitlogin
Defining Setable Forms
4 points by eds 6124 days ago | 7 comments
Forgive me if this was already discussed on the forums, but I was thinking about all the defset discussion on the forums a while ago, and while I remember a number of macros abstracting away the boilerplate of defset, I don't remember an actual proposition to integrate this into the official def.

In http://arclanguage.org/item?id=3112 for example, there is a def= which you could use as such:

  (def= caddr (val xs)
    (= (car (cdr (cdr xs))) val))
But while this is nice, I would really rather have pg integrate this into def:

  (def (= caddr) (val xs)
    (= (car (cdr (cdr xs))) val))
Is there any hope of getting this? (Is this what the "Control over sref" entry is for in the "What do want added" poll?)

(I also remember http://arclanguage.org/item?id=3595 which is very cool as well, but which I don't think is necessarily needed to get (def (= func) ...) to work.)



7 points by Darmani 6124 days ago | link

  (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.

-----

3 points by cooldude127 6124 days ago | link

yay! i wrote that def= macro. i too would like it CL style integrated into def. i simply didn't feel like rewriting def to accomodate it.

-----