Dan Bensen <randomgeek@cyberspace.net> wrote:
+---------------
| rocco.rossi@gmail.com wrote:
| > (setf (values a b c) (values-list '(2 3 5)))
|
| No, VALUES isn't quite that flexible.
+---------------
Uh... Actually, Sir, it certainly *is*!!
http://www.lisp.org/HyperSpec/Body/sec_5-1-2-3.html
5.1.2.3 VALUES Forms as Places
A values form can be used as a place, provided that each
of its subforms is also a place form.
...
(setf (values place-1 ...place-n) values-form)
For example:
> (deflex a 'a) ; Pardon my DEFLEX, less typing than (defvar *a* ...)
A
> (deflex b (list 'b 'bb 'bbb))
B
> (deflex c (vector 'c 'cc 'ccc 'cccc))
C
> (list a b c)
(A (B BB BBB) #(C CC CCC CCCC))
> (setf (values a (second b) (aref c 2)) (values-list '(2 3 5)))
2
3
5
> (list a b c)
(2 (B 3 BBB) #(C CC 5 CCCC))
>
+---------------
| I've never seen VALUES used anywhere except where the values
| are received by one of the multiple-value-* forms.
+---------------
Well, now you have! ;-} ;-}
+---------------
| You also can't use it as function arguments.
+---------------
You can, but of course you'll only pass the first one:
> (list (values 1 2 3) (values 4 5 6 7) (values 8 9) 10)
(1 4 8 10)
>
Though if you do want to pass *all* the values, have a look at:
http://www.lisp.org/HyperSpec/Body/speope_multiple-value-call.html
...
(multiple-value-call #'list 1 '/ (values 2 3) '/ (values) '/ (floor 2.5))
=> (1 / 2 3 / / 2 0.5)
-Rob
-----
Rob Warnock <rpw3@rpw3.org>
627 26th Avenue <URL:http://rpw3.org/>
San Mateo, CA 94403 (650)572-2607