Skip to content

Commit 1de6aaa

Browse files
committed
dot notation for slot-access
1 parent ed48e9f commit 1de6aaa

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

Diff for: dot-slot-value-access.lisp

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
;;; Dot notation for slot values
2+
3+
;;; Rainer Joswig, [email protected], 2012
4+
5+
6+
; Example
7+
;
8+
; #!turtle.drawing.pen-down-p
9+
;
10+
; expands to
11+
;
12+
; (slot-value (slot-value turtle 'drawing) 'pen-down-p)
13+
;
14+
15+
16+
(defun make-calls (string)
17+
(let ((symbols (reverse
18+
(mapcar (lambda (string)
19+
(intern string))
20+
(split-sequence '(#\.) string)))))
21+
(labels ((nest (list)
22+
(if (not (cddr list))
23+
`(slot-value ,(second list) ',(first list))
24+
`(slot-value ,(nest (cdr list))
25+
',(first list)))))
26+
(nest symbols))))
27+
28+
(defun read-instance-slot-value (stream subchar arg)
29+
(declare (ignore subchar arg))
30+
(make-calls (symbol-name (let ((*readtable* (copy-readtable nil)))
31+
(read stream)))))
32+
33+
(set-dispatch-macro-character
34+
#\# #\!
35+
#'read-instance-slot-value)
36+
37+

0 commit comments

Comments
 (0)