Christophe Turle wrote:
>
> It doesn't seem to work. Here the tests :
>
> CL-USER> `(a ,$(values 'x) b)
> (A (MULTIPLE-VALUE-LIST (VALUES 'X)) B)
>
> CL-USER> `(a ,$(values) b)
> (A (MULTIPLE-VALUE-LIST (VALUES)) B)
>
> CL-USER> `(a ,$(values 'x 'y) b)
> (A (MULTIPLE-VALUE-LIST (VALUES 'X 'Y)) B)
Aha, try this version. The code I posted is missing the splicing
unquote syntax around the (MULTIPLE-VALUE-LIST ...) form; the reader
should return
(SYSTEM::SPLICE (MULTIPLE-VALUE-LIST ...))
The corrected function is:
.(defun new-comma-reader (stream character)
. (let ((next-char (peek-char T stream)))
. (if (char= next-char #\$)
. (progn
. (read-char stream)
. (list 'system::splice (list 'multiple-value-list (read stream))))
. (funcall *old-comma-reader* stream character))))
Cool, thx !
So using your code, i can integrate it smoothly in my home cl :
#+clisp
(defvar *old-comma-reader* (get-macro-character #\,))
#+clisp
(defun new-comma-reader (stream char)
(let ((next-char (peek-char T stream)))
(if (or (char= next-char ··@)
(char= next-char #\.) )
(funcall *old-comma-reader* stream char)
(list 'system::splice `(multiple-value-list ,(read stream))) )))
#+clisp
(set-macro-character #\, #'new-comma-reader)
#| test cases
()
CL-USER> `(a ,(values) d)
(A D)
CL-USER> `(a ,(values 'b) d)
(A B D)
CL-USER> `(a ,(values 'b 'c) d)
(A B C D)
CL-USER> `(a ,(list 'b 'c) d)
(A (B C) D)
CL-USER> `(a ,@(list 'b 'c) d)
(A B C D)
CL-USER> `(a ,.(list 'b 'c) d)
(A B C D)
|#
no new syntax to learn. just an added functionnality ;)
--
___________________________________________________________
Christophe Turle.
sava preview http://perso.wanadoo.fr/turle/lisp/sava.html
(format nil ···@~a.~a" 'c.turle 'wanadoo 'fr)