Is there a reason multiple-value-bind only accepts symbols, not places?
And what would be the best way to do the equivalent with places? I can
write this, but it's a bit ugly:
(let ((a-and-b (multiple-value-list
(some-function-that-returns-two-values))))
(setf (slot-a x) (first a-and-b))
(setf (slot-b x) (second a-and-b)))
I'd much rather have something that would look like this:
(multiple-value-bind-extra ((slot-a x) (slot-b x))
(some-function-that-returns-two-values))
Of course I can define multiple-value-bind-extra, but before doing that
I wanted to know if something alike did not exist already.
<············@gmail.com> wrote:
> Is there a reason multiple-value-bind only accepts symbols, not places?
> And what would be the best way to do the equivalent with places? I can
> write this, but it's a bit ugly:
>
> (let ((a-and-b (multiple-value-list
> (some-function-that-returns-two-values))))
> (setf (slot-a x) (first a-and-b))
> (setf (slot-b x) (second a-and-b)))
Because that's not what binding means (have a look at the CLHS glossary).
The less ugly way to write this is:
(setf (values (slot-a x) (slot-b x))
(some-function-that-returns-two-values))
--
Juho Snellman
"Premature profiling is the root of all evil."
Juho Snellman wrote:
> Because that's not what binding means (have a look at the CLHS glossary).
Ok, but then the question only becomes, why do we have
"multiple-value-bind" rather than something like "multiple-value-setf".
But with the solution you provided, I can see that question is stupid.
> The less ugly way to write this is:
>
> (setf (values (slot-a x) (slot-b x))
> (some-function-that-returns-two-values))
Nice! My mind has not yet been warped enough to the Lisp way so that I
could think of this by myself. I find this beautiful. Thank you!
Philippe Lorin <············@gmail.com> writes:
> Juho Snellman wrote:
>> Because that's not what binding means (have a look at the CLHS glossary).
>
> Ok, but then the question only becomes, why do we have
> "multiple-value-bind" rather than something like
> "multiple-value-setf". But with the solution you provided, I can see
> that question is stupid.
Well, there is MULTIPLE-VALUE-SETQ. However it is generally good style
to do assignments with SETF. I.e. it's better to say (setf (car thing)
10) than (rplaca thing 10) and better to say (setf (values a b) (foo))
than (multiple-value-setq (a b) (foo)).
-Peter
--
Peter Seibel * ·····@gigamonkeys.com
Gigamonkeys Consulting * http://www.gigamonkeys.com/
Practical Common Lisp * http://www.gigamonkeys.com/book/
Philippe Lorin <············@gmail.com> writes:
> Is there a reason multiple-value-bind only accepts symbols, not
> places? And what would be the best way to do the equivalent with
> places? I can write this, but it's a bit ugly:
>
> (let ((a-and-b (multiple-value-list
> (some-function-that-returns-two-values))))
> (setf (slot-a x) (first a-and-b))
> (setf (slot-b x) (second a-and-b)))
>
>
> I'd much rather have something that would look like this:
>
> (multiple-value-bind-extra ((slot-a x) (slot-b x))
> (some-function-that-returns-two-values))
You want to name it MULTIPLE-VALUE-SETF
> Of course I can define multiple-value-bind-extra, but before doing
> that I wanted to know if something alike did not exist already.
There's already a MULTIPLE-VALUE-SETQ but of course, it only works
with symbols too.
--
__Pascal Bourguignon__ http://www.informatimago.com/
In deep sleep hear sound,
Cat vomit hairball somewhere.
Will find in morning.
"Marc Ordinas i Llopis" <····@nexe.org> writes:
> Would this be enough?
>
> (defmacro multiple-value-setf (places form)
> `(setf (values ,@places) ,form))
>
> Just a quick answer.
Exactly. This is why it is not included in the standard.
--
"Specifications are for the weak and timid!"
In article <··············@thalassa.informatimago.com>,
Pascal Bourguignon <····@mouse-potato.com> wrote:
> "Marc Ordinas i Llopis" <····@nexe.org> writes:
>
> > Would this be enough?
> >
> > (defmacro multiple-value-setf (places form)
> > `(setf (values ,@places) ,form))
> >
> > Just a quick answer.
>
> Exactly. This is why it is not included in the standard.
Then why is MULTIPLE-VALUE-SETQ included?
IIRC, SETF of VALUES was a late addition to the language. Before we
added it, we didn't have MULTIPLE-VALUE-SETF either.
--
Barry Margolin, ······@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***