Arc Forumnew | comments | leaders | submitlogin
1 point by Pauan 5039 days ago | link | parent

And if you want that behavior in Arc, here's a macro:

  (mac chain (x . body)
    (w/uniq u
      `(let ,u ,x
         ,@(map (fn ((f . args))
                  ;; could use list* but Arc 3.1 doesn't include it
                  `(,f ,u ,@args))
                body)
         ,u)))
And how to use it:

  (chain path
    (move-to 10 10)
    (stroke "red")
    (fill "blue")
    (ellipse 50 50))
Though... adding in syntax sugar for it would certainly be more convenient. Come to think of it, this would be quite convenient for arc2js:

  ;; Basic DOM              
  (chain (div)
    (set-attribute "bar" "qux")
    (append-child (div)))

  ;; jQuery
  (chain ($ "foo")
    (offset 10)
    (add-class "bar")
    (click (fn ...)))
Amusingly enough, this is similar to the JS "with" block, only without all the problems that "with" has.