Skip to content

Instantly share code, notes, and snippets.

@dastels
Created December 7, 2013 19:12
Show Gist options
  • Select an option

  • Save dastels/7847199 to your computer and use it in GitHub Desktop.

Select an option

Save dastels/7847199 to your computer and use it in GitHub Desktop.
Specification of frames in iLisp
(describe frame-syntax
(check '{a: 1} '(make-frame a: 1)))
(describe frame-rendering
(check (str (make-frame a: 1)) "{a: 1}"))
(describe naked-symbols
(check a: 'a:))
(describe frame-access
(check (get-slot {a: 1 b: 2 c: 3} a:) 1)
(check (get-slot {a: 1 b: 2 c: 3} b:) 2))
(describe frame-mutation
(let ((f {a: 1 b: 2 c: 3}))
(check (set-slot! f a: 5) 5)
(check (get-slot f a:) 5)))
(describe frame-method
(let ((f {a: 5
b: 2
foo: (lambda (x)
(+ x a))}))
(check (send f foo: 1) 6))
(let ((f {a: 5
b: 2
foo: (lambda (x)
(set! b (+ x a)))}))
(check (send f foo: 1) 6)
(check (get-slot f b:) 6)))
(describe prototypes
(let ((f {a: 2
b: 1})
(g {parent*: f
a: 3}))
(check (get-slot g b:) 1)
(check (get-slot g a:) 3)
(set-slot! g a: 1)
(check (get-slot g a:) 1)
(set-slot! g b: 10)
(check (get-slot g b:) 10))
(let ((adder {add: (lambda (x)
(+ x a))})
(incrementor {parent*: adder
a: 1}))
(check (send incrementor add: 3) 4)))
(describe new-slots
(let ((f {a: 1}))
(check (set-slot! f b: 5) 5)
(check (get-slot f b:) 5)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment