This extract is from the HyperSpec section about RESTART-CASE.
(defun read-new-value ()
(format t "Enter a new value: ")
(multiple-value-list (eval (read))))
Later on READ-NEW-VALUE is described as :INTERACTIVE function.
Why MULTIPLE-VALUE-LIST is necessary? Why not just use LIST instead?
In which circumstances it is essential and using simply LIST doesn't
work?
Thanks in advance
--
Vladimir Zolotykh
Vladimir Zolotykh <······@eurocom.od.ua> writes:
> Why MULTIPLE-VALUE-LIST is necessary? Why not just use LIST instead?
> In which circumstances it is essential and using simply LIST doesn't
> work?
As defined in the example, READ-NEW-VALUE can return a list of
several elements, if the user enters a form that returns multiple
values. RESTART-CASE will then use each of those elements as a
separate argument to the restart. This might be useful if the
elements were to be stored to a place that accepts multiple values:
(restart-case ...
(store-values (&rest new-values)
:interactive read-new-value
(setf (values foo bar) (values-list new-values))))
Multiple values cannot be directly given to a restart, but
encapsulating them in a list works around this restriction.
In VERIFY-OR-FIX-PERFECT-SUNDAE however, each restart accepts
only one argument. Thus, if the user enters a form that returns
multiple values, READ-NEW-VALUE returns a list with more than one
element, and the restart is invoked with an incorrect number of
arguments. I think that is wrong; any extra values returned by
forms should be silently ignored.[1] This could be done by using
LIST as you suggest, or by making the restart itself correct the
number of values like with VALUES-LIST above.
[1] However, see <http://www.cliki.net/Issue%20READER-MACRO-VALUES>.