Hi.
I'm learning Lisp and I'd be grateful if someone could help me with the
following problem.
I'm trying to determine a general method of combining multiple values into a
single list.
I have tried the following (unsuccessful) methods:
(list (values 1 2) (values 'a 'b))
(1 A)
(multiple-value-list (values 1 2) (values 'a 'b))
(1 2)
In the above instances, I'm trying to return the list (1 2 'a 'b).
Any help would be much appreciated.
Tony
I'm trying to determine a general method of combining multiple values
into a
single list.
>I have tried the following (unsuccessful) methods:
>
>(list (values 1 2) (values 'a 'b))
>
>(1 A)
>
>(multiple-value-list (values 1 2) (values 'a 'b))
>
>(1 2)
>
>In the above instances, I'm trying to return the list (1 2 'a 'b).
Here is the solution to the particular problem that you gave:
(append (multiple-value-list (values 1 2)) (multiple-value-list (values
'a 'b)))
--> (1 2 A B)
It's rather inelegant though. This is just crying out for a macro:
(multiple-multiple-value-list (values 1 2) (values 'a 'b) (values 'and
'so 'on))
--> (1 2 A B AND SO ON)
I haven't figured out how to write such a macro, though. Assuming it
would start like this...
(defmacro multiple-multiple-value-list (&rest rest) ...
I don't see how to splice the arguments, though.
"Eric Lavigne" <············@gmail.com> wrote in message news:<························@z14g2000cwz.googlegroups.com>...
> I'm trying to determine a general method of combining multiple values
> into a
> single list.
>
> >I have tried the following (unsuccessful) methods:
> >
> >(list (values 1 2) (values 'a 'b))
> >
> >(1 A)
> >
> >(multiple-value-list (values 1 2) (values 'a 'b))
> >
> >(1 2)
> >
> >In the above instances, I'm trying to return the list (1 2 'a 'b).
>
> Here is the solution to the particular problem that you gave:
>
> (append (multiple-value-list (values 1 2)) (multiple-value-list (values
> 'a 'b)))
> --> (1 2 A B)
>
> It's rather inelegant though. This is just crying out for a macro:
> (multiple-multiple-value-list (values 1 2) (values 'a 'b) (values 'and
> 'so 'on))
> --> (1 2 A B AND SO ON)
>
> I haven't figured out how to write such a macro, though. Assuming it
> would start like this...
> (defmacro multiple-multiple-value-list (&rest rest) ...
>
> I don't see how to splice the arguments, though.
Here's one way to do it:
(defmacro multiple-multiple-value-list (&body body)
`(append ,@(mapcar #'(lambda (v) `(multiple-value-list ,v)) body)))
I hope I didn't make a fool out of myself now! :)
Eric Lavigne wrote:
> It's rather inelegant though. This is just crying out for a macro:
> (multiple-multiple-value-list (values 1 2) (values 'a 'b) (values 'and
> 'so 'on))
> --> (1 2 A B AND SO ON)
>
> I haven't figured out how to write such a macro, though. Assuming it
> would start like this...
> (defmacro multiple-multiple-value-list (&rest rest) ...
(defmacro multiple-multiple-value-list (&rest value-producing-forms)
(cond
((null value-producing-forms) 'nil)
((null (rest value-producing-forms))
`(multiple-value-list ,(first value-producing-forms)))
(t `(nconc (multiple-value-list ,(first value-producing-forms))
(multiple-multiple-value-list . ,(rest value-producing-forms))))))
will do it, for instance.
--
Gareth McCaughan
.sig under construc
"Tony" <··········@email.com> writes:
> Hi.
>
> I'm learning Lisp and I'd be grateful if someone could help me with the
> following problem.
>
> I'm trying to determine a general method of combining multiple values into a
> single list.
>
> I have tried the following (unsuccessful) methods:
>
> (list (values 1 2) (values 'a 'b))
>
> (1 A)
>
> (multiple-value-list (values 1 2) (values 'a 'b))
>
> (1 2)
>
> In the above instances, I'm trying to return the list (1 2 'a 'b).
>
> Any help would be much appreciated.
>
Not quite sure I understand exactly what you want as
CL-USER> (list 1 2 'a 'b)
(1 2 A B)
CL-USER>
seems to do what you are after or are you after something which will
return a flat list even when the arguments might themselves be lists
or some other requirement I'm not getting from your problem
description?
Tim
--
Tim Cross
The e-mail address on this message is FALSE (obviously!). My real e-mail is
to a company in Australia called rapttech and my login is tcross - if you
really need to send mail, you should be able to work it out!
On Sun, 17 Jul 2005 14:23:49 +1000, Tony wrote:
> Hi.
> I'm learning Lisp and I'd be grateful if someone could help me with the
> following problem.
> I'm trying to determine a general method of combining multiple values into a
> single list.
> I have tried the following (unsuccessful) methods:
> (list (values 1 2) (values 'a 'b))
> (1 A)
> (multiple-value-list (values 1 2) (values 'a 'b))
> (1 2)
I'd expect an error.
> In the above instances, I'm trying to return the list (1 2 'a 'b).
> Any help would be much appreciated.
(multiple-value-call #'list (values 1 2) (values 'a 'b))
--
Don't worry about people stealing your ideas. If your ideas are any good,
you'll have to ram them down people's throats.
-- Howard Aiken
(setq reply-to
(concatenate 'string "Paul Foley " "<mycroft" '(··@) "actrix.gen.nz>"))