Skip to content

Instantly share code, notes, and snippets.

@rocketnia
Created October 6, 2013 01:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rocketnia/6848219 to your computer and use it in GitHub Desktop.
Save rocketnia/6848219 to your computer and use it in GitHub Desktop.
Arc code to define places (i.e. getter-setters) with an example definition of 'push.
; Copyright 2013 Ross Angle
;
; This code is released under the
; Perl Foundation's Artistic License 2.0.
; This code is an example for a forum post at
; <http://arclanguage.org/item?id=18051>.
(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))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment