Nyquist / XLISP 2.0 - Contents | Tutorials | Examples | Reference

# cl:multiple-value-call

The cl:multiple-value-call macro applies a function to a list of return values:

(cl:multiple-value-call function [expr1 ...])
  function - a Lisp expression evaluating to a function call
  exprN - arbitrary Lisp expressions
  returns - the values returned by the function

    (defmacro cl:multiple-value-call (function &rest exprs)
      (let (args)
        (dolist (expr exprs)
          (setq  cl:*multiple-values* nil)
          (let* ((result (eval expr)))
            (if cl:*multiple-values*
                (dolist (rslt *rslt*) (push rslt args))
                (push result args))))
        (setq args (reverse args))
        `(progn
           (setq cl:*multiple-values* nil)
           (apply ,function ',args)))

The cl:multiple-value-call macro first evaluates the expressions and collects all return values in a single list, then the 'function' form is evaluated and the resulting function call is applied to the list of values.

Before applying the function to the list of values the cl:*multiple-values* variable is set to NIL, the final value of cl:*multiple-values* depends on the 'function' argument.

Examples:

    > (funcall #'+
        (cl:values 1 2)
        (cl:values 3 4))
    4  ; (apply #'+ (1 3))

    > (cl:multiple-value-call #'+
        (cl:values 1 2)
        (cl:values 3 4))
    10  ; (apply #'+ (1 2 3 4))

Back to top

Nyquist / XLISP 2.0 - Contents | Tutorials | Examples | Reference