From: Christophe Turle
Subject: mv quasi-quotation
Date: 
Message-ID: <41f6aa80$0$22485$626a14ce@news.free.fr>
is there a multiple-value quasi-quotation somewhere ?

like :

`(a ,(values 'x) b)    =>  (a x b)
`(a ,(values) b)       =>  (a b)
`(a ,(values 'x 'y) b) =>  (a x y b)


Even a Clisp specific implementation.

-- 
___________________________________________________________
Christophe Turle.
sava preview http://perso.wanadoo.fr/turle/lisp/sava.html
(format nil ···@~a.~a" 'c.turle 'wanadoo 'fr) 

From: Kaz Kylheku
Subject: Re: mv quasi-quotation
Date: 
Message-ID: <1106696413.703147.205900@c13g2000cwb.googlegroups.com>
Christophe Turle wrote:
> is there a multiple-value quasi-quotation somewhere ?
>
> like :
>
> `(a ,(values 'x) b)    =>  (a x b)
> `(a ,(values) b)       =>  (a b)
> `(a ,(values 'x 'y) b) =>  (a x y b)
>
>
> Even a Clisp specific implementation.

Here are the pieces for a CLISP-specific implementation. Hope Google
Groups Beta doesn't munge the formatting.

It would be a lot simpler if you could live without the comma; in other
words $X rather than ,$X. But in some ways this is better because it
doesn't conflict with custom readers for the $ character.

As you can see the problem with this is that the , reader is
pervasively active. CLISP's usual reader knows when it's in a backquote
context, and so it can throw error messages otherwise. That logic is
not duplicated here in the wrapping reader, so the ,$ translation
happens anywhere.

One sneaky way to get the error handling would be to always call the
built-in reader, and then post-filter its output. How? You peek at the
next character, as is done now. If it's a dollar sign, then you swallow
it. Call the old reader, which will produce an unquote. Rip apart the
unquote, and convert it to the MULTIPLE-VALUE-LIST form and return
that.

Then, one finishing touch: check for the ,·@FORM case, for which you
can signal some error. After eating the $ character, peek to see
whether there is a @ character before calling the old comma reader.


;;;
;;; CLISP-specific hack to enable ,$ syntax in backquotes.
;;; This syntax splices multiple values. In other words,
;;;
;;; `(... ,$FORM ..)
;;;
;;; behaves like
;;;
;;; `(... ,@(multiple-value-list FORM) ...)
;;;
;;; Kaz Kylheku <···@ashi.footprints.net>
;;; January 25, 2005
;;;

(defvar *old-comma-reader* nil)

(defun new-comma-reader (stream character)
(let ((next-char (peek-char t stream)))
(if (char= next-char #\$)
(progn
(read-char stream)
(list 'multiple-value-list (read stream)))
(funcall *old-comma-reader* stream character))))

(defun install-hack ()
(unless *old-comma-reader*
(setf *old-comma-reader* (get-macro-character #\,))
(set-macro-character #\, #'new-comma-reader)))

(defun uninstall-hack ()
(when *old-comma-reader*
(set-macro-character #\, *old-comma-reader*)
(setf *old-comma-reader* nil)))
From: Jens Axel Søgaard
Subject: Re: mv quasi-quotation
Date: 
Message-ID: <41f6f1a6$0$209$edfadb0f@dread12.news.tele.dk>
Kaz Kylheku wrote:

> Here are the pieces for a CLISP-specific implementation. Hope Google
> Groups Beta doesn't munge the formatting.

It removes initial white space. The trick is therefor to insert
say a single dot in the first column before posting.

-- 
Jens Axel Søgaard
From: Wade Humeniuk
Subject: Re: mv quasi-quotation
Date: 
Message-ID: <WgyJd.35783$Qb.12403@edtnps89>
Christophe Turle wrote:
> is there a multiple-value quasi-quotation somewhere ?
> 
> like :
> 
> `(a ,(values 'x) b)    =>  (a x b)
> `(a ,(values) b)       =>  (a b)
> `(a ,(values 'x 'y) b) =>  (a x y b)
> 
> 
> Even a Clisp specific implementation.
> 

CL-USER 12 : 1 > `(a ,@(multiple-value-list (values 'x 'y)) b)
(A X Y B)

CL-USER 13 : 1 >

Wade
From: Harald Hanche-Olsen
Subject: Re: mv quasi-quotation
Date: 
Message-ID: <pcohdl5uspl.fsf@shuttle.math.ntnu.no>
+ Wade Humeniuk <··················@telus.net>:

| CL-USER 12 : 1 > `(a ,@(multiple-value-list (values 'x 'y)) b)

Hmm, and I had just recommended using ,. instead.  Or are compilers
generally smart enough to recognize that reusing the list from
multiple-value-list is safe in this context?

-- 
* Harald Hanche-Olsen     <URL:http://www.math.ntnu.no/~hanche/>
- Debating gives most of us much more psychological satisfaction
  than thinking does: but it deprives us of whatever chance there is
  of getting closer to the truth.  -- C.P. Snow
From: Christophe Turle
Subject: Re: mv quasi-quotation
Date: 
Message-ID: <41f6bf48$0$22486$626a14ce@news.free.fr>
"Harald Hanche-Olsen" <······@math.ntnu.no> a �crit dans le message de news: 
···············@shuttle.math.ntnu.no...
>+ Wade Humeniuk <··················@telus.net>:
>
> | CL-USER 12 : 1 > `(a ,@(multiple-value-list (values 'x 'y)) b)

CL-USER> `(a ,@(multiple-value-list (values 'x 'y)) b)
(A X Y B)
CL-USER> `(a ,@(multiple-value-list (values 'x)) b)
(A X B)
CL-USER> `(a ,@(multiple-value-list (values)) b)
(A B)

It works ;) but 2 things annoyed me when i had thought of it

1- Efficiency : is the compiler smart enough to not build unneeded lists.

2- how to reduce the typing ? can a reader macro-character expands to 
,@(multiple-value-list ...)
   It's a shame that ` has no standard list form like in Scheme.

but point 2 can be accomplished in Clisp, and 1 is just efficiency. So it is 
a solution. Thx.

In fact my true goal was : `(a ,$(foo) b) where foo can return 0, 1 or more 
values.


> Hmm, and I had just recommended using ,. instead.  Or are compilers
> generally smart enough to recognize that reusing the list from
> multiple-value-list is safe in this context?

,. doesn't work for the two other cases (at least in Clisp)

And i surely don't want that 'foo' always returns a list. We are too lucky 
to have 'values' to not use them.


-- 
___________________________________________________________
Christophe Turle.
sava preview http://perso.wanadoo.fr/turle/lisp/sava.html
(format nil ···@~a.~a" 'c.turle 'wanadoo 'fr) 
From: Harald Hanche-Olsen
Subject: Re: mv quasi-quotation
Date: 
Message-ID: <pcod5vtul6r.fsf@shuttle.math.ntnu.no>
+ "Christophe Turle" <······@nospam.com>:

| > Hmm, and I had just recommended using ,. instead.  Or are compilers
| > generally smart enough to recognize that reusing the list from
| > multiple-value-list is safe in this context?
| 
| ,. doesn't work for the two other cases (at least in Clisp)

That must be a bug in Clisp, then.  Please send them a bug report.

| And i surely don't want that 'foo' always returns a list. We are too
| lucky to have 'values' to not use them.

Like all tools, this one is to be used where it is useful.

As far as I can tell, VALUES basically has two uses:

- For functions where you're often only interested in a single value,
  but where extra values may sometimes come in handy, and
- to save you the extra consing that would be required to return
  several values as a list, only to take the list apart in the caller
  to get at the values.

As I alluded to in my other post, in this case you get neither of
these benefits from using VALUES in this case.  So the only remaining
reason for doing so is because you wish to merge in multiple values
from a function that already returns multiple values for another
reason.  And for that, ,.(multiple-value-list (...)) is just what the
doctor ordered - provided, of course, that it works in the
implementation you're using.

-- 
* Harald Hanche-Olsen     <URL:http://www.math.ntnu.no/~hanche/>
- Debating gives most of us much more psychological satisfaction
  than thinking does: but it deprives us of whatever chance there is
  of getting closer to the truth.  -- C.P. Snow
From: Paul F. Dietz
Subject: Re: mv quasi-quotation
Date: 
Message-ID: <yNqdnamraNYBFmrcRVn-hQ@dls.net>
Christophe Turle wrote:

> 1- Efficiency : is the compiler smart enough to not build unneeded lists.

Efficiency in backquoted forms almost never matters.  I use ,@ almost
exclusively vs. ,. since I don't want to waste time debugging sharing
problems.

> 2- how to reduce the typing ? can a reader macro-character expands to 
> ,@(multiple-value-list ...)
>    It's a shame that ` has no standard list form like in Scheme.

(defmacro mvl (form) `(multiple-value-list ,form))

    ... ,@(mvl (values ...)) ...

	Paul
From: Harald Hanche-Olsen
Subject: Re: mv quasi-quotation
Date: 
Message-ID: <pcollahusum.fsf@shuttle.math.ntnu.no>
+ "Christophe Turle" <······@nospam.com>:

| is there a multiple-value quasi-quotation somewhere ?
| 
| like :
| 
| `(a ,(values 'x) b)    =>  (a x b)
| `(a ,(values) b)       =>  (a b)
| `(a ,(values 'x 'y) b) =>  (a x y b)

Seems to me there is nothing to gain by this over using the
,. facility.  After all, cons cells need to be allocated for the new
part of the list anyway, right?

Instructive example:

CL-USER> (let ((foo (list 'x 'y)))
	   (values `(a ,.foo b) foo))
(a x y b)
(x y b)

Of course, if the reason you want this is because you already have a
function returning multiple values and you wish to splice them into a
list, use ,.(multiple-value-list (function-returning-multiple-values)).

-- 
* Harald Hanche-Olsen     <URL:http://www.math.ntnu.no/~hanche/>
- Debating gives most of us much more psychological satisfaction
  than thinking does: but it deprives us of whatever chance there is
  of getting closer to the truth.  -- C.P. Snow