[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Issue: NTH-VALUE (Version 1)
- To: cl-cleanup%sail.stanford.edu@multimax
- Subject: Issue: NTH-VALUE (Version 1)
- From: Dan L. Pierson <pierson%mist@multimax.ARPA>
- Date: Tue, 16 Aug 88 18:43:11 EDT
Issue: NTH-VALUE
References: Multiple values, pp. 133-139
Category: ADDITION
Edit history: Version 1 by Pierson 8/16/88
Status: For Internal Discussion
Problem description:
The set of actions on multiple values in Common Lisp is incomplete.
Proposal (NTH-VALUE:ADD):
Add a new macro:
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 compatability with NTH and NTHCDR.
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 fills a hole in the initial definition of Common Lisp and permits
clearer code in some circumstances.
Current practice:
I don't know of any implementation that provides this feature.
Cost to Implementors:
A simple new macro needs to be written. In addition, most
implementations will choose to implement compiler hooks so that code
written with NTH-VALUE will be as efficient as possible.
Cost to Users:
None, this is an upward-compatible change.
Cost of non-Adoption:
This feature won't be available to portable programs.
Benefits:
This makes some code that uses multiple values easier to read and
write. In addition, it may be easier for implementations to optimize
expressions which use NTH-VALUE instead of using MULTIPLE-VALUE-BIND
and ignoring the unwanted values.
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.
------- End of Forwarded Message