[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Issue: NTH-VALUE (Version 2)
- To: CL-Cleanup@SAIL.Stanford.EDU
- Subject: Issue: NTH-VALUE (Version 2)
- From: Kent M Pitman <KMP@STONY-BROOK.SCRC.Symbolics.COM>
- Date: Sat, 1 Oct 88 20:46 EDT
- In-reply-to: <8808162243.AA06571@mist.UUCP>
Very minor changes per discussion...
- expanded the Problem Description slightly.
- changed Proposal to be more explict about order of argument evaluation
- minor reformatting and rewording in places to make things clearer
and/or remove first-person usages from Pierson's writeup.
-----
Issue: NTH-VALUE
References: Multiple values, pp. 133-139
Category: ADDITION
Edit history: 16-Aug-88, Version 1 by Pierson
01-Oct-88, Version 2 by Pitman (minor edits)
Status: For Internal Discussion
Problem description:
The set of operations on multiple values in Common Lisp is incomplete:
The 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.
Proposal (NTH-VALUE:ADD):
Add a new macro NTH-VALUE, described as
NTH-VALUE n form [Macro]
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.
Test Cases/Examples:
With this proposal 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))
Rationale:
This corrects the stated problem.
Current practice:
No implementation is known to provide this feature.
Cost to Implementors:
Writing the macro version is fairly straightforward.
Most 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.
Cost to Users:
None, this is an upward-compatible change.
Cost of non-Adoption:
The occassional code where this comes up may be one or more of
clumsier to write, more difficult to read, or less efficient.
Benefits:
The cost of non-adoption is avoided.
Aesthetics:
While it does add another function to the language it removes
some need for the hairier multiple-value forms.
Discussion:
Pitman proposed this in the very late pre-CLtL days. It was
rejected then because it was too late in the cycle.
Pitman, Pierson, and Masinter have voiced support for this
proposal.
vanRoggen and Fahlman don't really think this feature is
necessary, but don't actively oppose its inclusion.