Arc Forumnew | comments | leaders | submitlogin
3 points by cooldude127 6122 days ago | link | parent

Here is a macro called def= that will do basically what the equivalent CL defun would:

  (def fix-body (gens args body)
    (let genargs (map list args gens)
      (if (alist body)
          (map [fix-body gens args _] body)
          (find body args)
          (list 'unquote (alref genargs body))
          body)))

  (mac def= (name (val . args) . body)
    (let gens (map [uniq] args)
      (list 'defset name args
            (list 'w/uniq gens
                  (list 'list
                        (cons 'list
                              (flat (map list gens args)))
                        `(list ',name ,@gens)
                        (list 'quasiquote (join (list 'fn (list val))
                                                (fix-body gens args body))))))))
Here is an example definition for a caddr setter:

  (def= caddr (val xs)
    (= (car (cdr (cdr xs))) val))
Any improvements are welcome.