Created
October 6, 2013 01:29
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; 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