Arc Forumnew | comments | leaders | submitlogin
3 points by rntz 5942 days ago | link | parent

This won't work if you want to define a function called 'o. Reason: (let var val ...) becomes ((fn (var) ...) val), and if var is (o ...), it becomes ((fn ((o ...)) ...) val). (o ...) is interpreted as an optional parameter, which disables destructuring.

Destructuring in lets is a nice idea, and using this with nil is a cool hack, but until and unless this behavior is changed, don't rely on it in macros - it can cause unexpected code breakage. A better way to do it would be the following (my 'fwithr is your 'mrec).

    (mac withr (bindings . body)
      (let bindings (pair bindings)
        `(with ,(mappend [list car._ nil] bindings)
           ,@(mapeach b bindings
               `(set ,@b))
           ,@body)))

    (mac fwithr (fns . body)
      `(withr
         ,(mappend [list car._ `(fn ,@cdr._)] fns)
         ,@body))
Edit: It seems almkglor has already done something like this, but his also has the "let doesn't always destructure" bug: http://arclanguage.org/item?id=7387