[quiz] [QUIZ 3] reader macro
Matt Pillsbury
mtbp at rci.rutgers.edu
Wed Jul 11 01:31:34 UTC 2007
On Jul 10, 2007, at 11:03 , Larry Clapp wrote:
> Send answers to the list, preferably with at least one working test
> case displayed, e.g. something like
> cl-user> #"\w \" \s"
> "\\w \" \\s"
Well, I ended up doing something slightly different.
(defun |#?-READER| (s c n)
(declare (ignore c n))
(let ((term (read-char s)))
(with-output-to-string (string)
(loop
:for char := (read-char s)
:until (char= char term)
:if (and (char= char #\\)
(char=
(peek-char nil s)
term))
:do
(write-char (read-char s) string)
:else :do
(write-char char string)))))
(set-dispatch-macro-character #\# #\? #'|#?-READER|)
This means that whatever character follows the #? becomes the
delimeter, like so:
CL-USER> #?"foo\"bar"
"foo\"bar"
CL-USER> #?%foo"bar%
"foo\"bar"
CL-USER> #?%foo\\bar%
"foo\\\\bar"
CL-USER> #?%foo\"bar%
"foo\\\"bar"
Cheers,
Pillsy
More information about the Quiz
mailing list