Kazimir Majorinc wrote:We have that
(first '())=(first '(nil))=nil and
(rest '())=(rest '(nil))=(), but not
'()='(nil).
It looks like some kind of anomaly.
What others think?
In CL it is similar, in Scheme (first '()) returns error
and it appears more reasonable to me.
I'm sure it was previously discussed, but I wasn't there.
My logical thinking says that if
then any non-existent condition, whether first or rest, should return the same value, nil.
The question here becomes, does the empty list have a first element or not? The list '(nil) does have a first element, nil. If the empty list does have a first element, then said first element must be nil, because nil is the return value from the evaluation, the same as the return value for '(nil). However, if the the first element of the empty list is just the empty list, then the first value of the empty list is itself.
When I look at the empty list, I see no distinction between the non-existing first element and the non-exisitng rest elements, so expect to see exactly the same value returned, whether it be nil or the empty set or some other arbitrary value. (In this case, my preference is for rest to return nil if there is nothing to return; I think returning the empty list for ANY single-element list is a logic error under the current implementation. However, my REAL preference is to ALWAYS return a list from first or rest; see the end of the post.)
However, it is clear that the definition for rest returns the empty list for every list comprising a single element. So, based on this understanding of rest, the empty list MUST contain a single element, hence must return that element via first, in the same fashion that (first '(nil)) returns that first element, nil. That, therefore, would make the defined return result of nil being incorrect.
In addition, if we accept the above logic that (first '()) returns (), this enables applying the same logical rules to evaluating both (first '()) and (first '(nil)). Then, the return value from (first '()), that APPEARS to be (), has a subtley diffrerent meaning than other instances of () that mean the empty set. In the first case, it is the FIRST ELEMENT of the empty list, while in the second case it IS the empty list. Likewise the evaluaton of the FIRST ELEMENT of the list '(nil) has a sublte diffrenece from the ACTUAL value nil.
But in the end, what I would really prefer is that first and rest ALWAYS return a list, except of course if an error occurs. So, if (length (first list)) or (length (rest list)) return 0, then I want the result of first and rest to return the empty list. I want to see every result of first returned as a list either with 1 element or else the empty list, analagous to the results of rest as a list,