-
Notifications
You must be signed in to change notification settings - Fork 1
/
olisp_example.tl
32 lines (30 loc) · 1.14 KB
/
olisp_example.tl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
; A simple demonstration of object facilities
;
; Depends on olisp.tl
(class new-object (state)
(inst-var hidden tl-#t)
(methods
(print () (display #message))
(getstate () state)
(gethidden () hidden)
(setstate (newstate) (set! state newstate))
(sethidden (newhidden) (set! hidden newhidden))
(showenv () (display (if hidden '"(hidden)" (tl-env))))
(#method-missing (method . args) `("I am method" ,method "with args" @args))
)
)
(define object (new-object 55))
(define other-object (new-object 'aa))
(display '"class of object" (typenameof object) (typeof object))
(display '"other object state" (call other-object 'getstate))
(display '"old state" (call object 'getstate))
(call object 'setstate 77)
(display '"new state" (call object 'getstate))
(display 'env (call object 'showenv))
(display '"old hidden" (call object 'gethidden))
(call object 'sethidden #f)
(display 'env (call object 'showenv))
(display '"new hidden" (call object 'gethidden))
(display '"state according to inst-eval" (inst-eval object 'state))
(display '"missing method" (call object 'oops 1 2 3))
(display '"other object state" (call other-object 'getstate))