Arc Forumnew | comments | leaders | submitlogin
1 point by fallintothis 5599 days ago | link | parent

Is this the version I should use?

You can if you want. It works.

  arc> (let a '(prn 5)
         (once-only (a)
           `(+ ,a 1)))
  (with (gs2595 (prn 5)) (+ gs2595 1))
Note that the parameter list doesn't work like w/uniq, where you can have a single argument with no parentheses. i.e.,

  arc> (let a '(prn 5)
         (once-only a
           `(+ ,a 1)))
  Error: "Can't take car of a"
This was fixed in the Anarki version (http://github.com/nex3/arc/blob/master/lib/util.arc#L374), but that version uses Anarki-specific utilities. The fix is still vanilla-Arc, if you want it:

  (mac once-only (names . body)
    (withs (names (check names alist (list names))
            gensyms (map1 [uniq] names))
      `(w/uniq ,gensyms
        `(with ,(list ,@(mappend list gensyms names))
          ,(with ,(mappend list names gensyms)
            ,@body)))))

  arc> (let a '(prn 5)
         (once-only a
           `(+ ,a 1)))
  (with (gs1724 (prn 5)) (+ gs1724 1))
My definition of on seems to eval the list only once anyway

Yeah, your definition's fine because each already handles the multiple-eval situation.

Side note:

  (zap [+ 1 _] index)
is equivalent to

  (zap + index 1)
which is equivalent to

  (++ index)
Just so you know.


1 point by akkartik 5599 days ago | link

D'oh. You know, I actually tried (zap ++ index) first. Don't know what I was thinking.

Thanks for the (zap + index 1) trick.

-----