|
|
|
|
|
by kazinator
3426 days ago
|
|
Some Lisp designers are listening: $ cat animal.tl
(defstruct animal nil
(:static legs nil)
(:method speak (self something)
(pprinl something)))
(defstruct dog animal
(:static legs 4)
(:method speak (self something)
(call-super-method self 'speak something)
(pprinl "Woof!")))
$ txr -i animal.tl
1> (defvar d1 (new dog))
d1
2> (defvar d2 (new dog))
d2
3> d1.legs
4
4> (set d2.legs 5) ;; legs is static: i.e. class-wide
5
5> d1.legs ;; all dogs have 5 legs now
5
6> d1.(speak "hey!")
hey!
Woof!
"Woof!"
7>
Next: 7> 'a.b.c.d
a.b.c.d
8> (car 'a.b.c.d)
qref
9> (cdr 'a.b.c.d)
(a b c d)
10> '(qref a b c d) ;; qref ::= "qualified reference"
a.b.c.d
11> '(qref a b (c x y) d)
a.b.(c x y).d
12> '(qref (qref a b) c)
(qref a.b c)
qref is syntax, targetted by a macro definition: 13> (macroexpand '(qref a b c))
(slot (slot a 'b)
'c)
We can hijack it in data for our own use: 14> '(www.google.com "blah")
(www.google.com "blah")
15> (caar '(www.google.com "blah"))
qref
16> (cdar '(www.google.com "blah"))
(www google com)
The TXR Lisp scripting language removes most of the Lisp micro-stumbling-blocks in everyday coding, providing the above notation, plus array access with ranges, and nice "string quasiliteral" notation for interpolated strings. 17> [mapcar succ "abcd"]
"bcde"
18> ["abcdefg" 0]
#\a
19> ["abcdefg" 0..3]
"abc"
20> ["abcdefg" -2..:]
"fg"
21> (car 'a..b)
rcons
22> (cdr 'a..b)
(a b)
23> '(rcons a b)
a..b
24> (rcons 1 2)
#R(1 2)
25> ["abcd" #R(1 3)]
"bc"
26> ["abcde" '(0 2 4 6)]
"ace"
|
|