Arc Forumnew | comments | leaders | submitlogin
2 points by rocketnia 3862 days ago | link | parent

"Perhaps this means push shouldn't be a macro?"

In Arc, my immediate approach would be to define 'push as a macro, but also to give it a procedure version that's just a little more verbose. Then we can extend the procedure version and leave the macro version alone.

Here's some working Arc 3.1 code, which calls the macro "my-push", rather than overwriting Arc's own 'push:

  (mac place (p)
    (w/uniq new-val
     `(make-place (fn () ,p) (fn (,new-val) (= ,p ,new-val)))))
  
  (def make-place (getter setter)
    (annotate 'place (list getter setter)))
  
  (def place-get (place)
    (rep.place.0))
  
  (def place-set (place new-val)
    rep.place.1.new-val)
  
  (defset place-get (place)
    (w/uniq g-place
      `((,g-place ,place)
        (place-get ,g-place)
        [place-set ,g-place _])))
  
  
  (mac my-push (elem stack)
    `(fn-push ,elem (place ,stack)))
  
  (def fn-push (elem stack)
    (zap [cons elem _] place-get.stack))
Here's a Gist of this code: https://gist.github.com/rocketnia/6848219