The less-familiar parts of Lisp for beginners — multiple-value-call

Continuing the series of less commonly-encountered Lisp features, multiple-value-call.  This function is much like funcall, but over multiple values.  If functions returning multiple values is unfamiliar to you, check the brief digression on the topic of values in this earlier post.

When funcall is invoked, if any of the arguments are forms, those forms are evaluated and the primary value is used in the function invocation.  Any additional values are discarded.  The multiple-value-call special operator captures all values returned by those forms and inserts them, in order, in the argument list before calling the function.  This is best illustrated with a simple example:
 

CL-USER> (funcall '+ (values 1 10) (values 1 20))
2
CL-USER> (funcall 'list (values 1 10) (values 1 20))
(1 1)
CL-USER> (multiple-value-call '+ (values 1 10) (values 1 20))
32
CL-USER> (multiple-value-call 'list (values 1 10) (values 1 20))
(1 10 1 20)

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

*

反垃圾邮件 / Anti-spam question * Time limit is exhausted. Please reload CAPTCHA.