NTH-VALUEThe only ways to retrieve just one of several return values (other than the first) are:
- Bind several variables and then ignore all but one. eg, (MULTIPLE-VALUE-BIND (X Y Z) <exp> (DECLARE (IGNORE X Y)) Z) This is somewhat cumbersome to write and not perspicuous.
- Get a list of all return values and select from that. eg, (THIRD (MULTIPLE-VALUE-LIST <exp>)) This is somewhat cumbersome, not perspicuous, and creates needless garbage.
NTH-VALUE, described as
NTH-VALUE n form [Macro]
N must be a non-negative integer. Evaluates the FORM and returns the Nth value returned by the form as a single value. N is 0-based, i.e. the first returned value is value 0 (for consistency with NTH and NTHCDR). Both N and FORM are evaluated, in left-to-right order.
NTH-VALUE returns NIL if N is greater than or equal to the number of values returned by FORM.
MOD could be defined as:
(DEFUN MOD (NUMBER DIVISOR) (NTH-VALUE 1 (FLOOR NUMBER DIVISOR)))
The same code would currently be:
(DEFUN MOD (NUMBER DIVISOR) (MULTIPLE-VALUE-BIND (DIVIDEND REMAINDER) (FLOOR NUMBER DIVISOR) (DECLARE (IGNORE DIVIDEND)) REMAINDER))
TI Explorer and LMI Lambda have this feature.
Some will choose to implement compiler hooks so that code written with NTH-VALUE will be as efficient as possible. This may involve some additional work, but presumably nothing major.
There was not strong sentiment for including this feature in Common Lisp, but no active opposition.
Comments at the October 1988 X3J13 meeting:
"Trivial, gratuitous."
"Not trivial -- allows index computation. Hard to do this in a portable, efficient way."
"Says he has an NTH-VALUE macro for a portable system that he uses (which exploits the computed index feature) and that it's a gross kludge in one implementation to make it efficient."