16 lines
522 B
Common Lisp
16 lines
522 B
Common Lisp
;;; MACROS 5: READER MACROS, A TASTER (solution)
|
|
|
|
(defun maybe-reader (stream sub-char num-arg)
|
|
(declare (ignore sub-char num-arg))
|
|
(list 'maybe (read stream)))
|
|
|
|
(set-dispatch-macro-character #\# #\? #'maybe-reader)
|
|
|
|
;;; ------------------------------------------------------------------
|
|
;;; Checks. Read them - they tell you what to aim for - but leave
|
|
;;; them unchanged.
|
|
;;; ------------------------------------------------------------------
|
|
|
|
(check-equal '(maybe red) '#?red)
|
|
(check-equal '(maybe (1 2)) '#?(1 2))
|