Previous chapter: #1: Collection Class-For-Copy (Clarification)

Dylan Design Notes: #2: First, Second, Third, Last Default (Addition)

Dylan Design Notes

#2: First, Second, Third, Last Default (Addition)

Version 1, March 1993

This design note adds a default: keyword argument to the specification of the functions first, second, third, and last. This change removes a possible source of confusion by making these functions more consistent with the function element.


Add a default: keyword argument to the functions first, second, third, and last. Change the description of first, second, and third on page 110 of the Dylan manual to read as follows:

Each of these functions returns the indicated element of the sequence. If the sequence is too short to contain such an element, then the behavior depends on whether the default argument was supplied. If the default argument was supplied, its value is returned; otherwise, an error is signaled.

Replace the second sentence of the description of last on page 110 of the manual with the following:

If the sequence is empty, then the behavior of last depends on whether it was called with a default argument. If the default argument was supplied, its value is returned; otherwise, an error is signaled.


Notes:

Many implementations will want to compile away the keyword argument. However, they should already have technology to do this for the implementation of element, so there isn't much added cost here.

This design note does not address the behavior of last on unbounded sequences, including the effect of the default: keyword when last is called on unbounded sequences.

Next chapter: #3: Make Class Specification (Addition)