Q: Is There Any Negation in English Language? A: No!

Notices and updates
Post Reply
Kazimir Majorinc
Posts: 388
Joined: Thu May 08, 2008 1:24 am
Location: Croatia
Contact:

Q: Is There Any Negation in English Language? A: No!

Post by Kazimir Majorinc »

(exists nil? '(1 2 nil 3)) => nil
(exists nil? '(1 2 3)) => nil


i.e. exists doesn't return sensible result for predicate nil?. I could replace this particular (exists nil? ...) with (find nil ...) but exists also doesn't work for all other predicates satisfied by nil, because returned nil cannot be interpreted. Unfortunately, there are numerous such cases, and some are important.

(exists logical-constant? '(x y z nil true)) => nil


I think that exists should return only true and false (nil), just like its dual for-all. Other part of the functionality, find-the-first-satisfying can be defined independently. (Overloading existing find causes the problems similar to existing ones.) Alternatively, index of the first element satisfying predicate, or even pair (index value) could be returned from exists - instead of value. I guess that one function - one functionality approach has the least chance to cause problems.

Lutz
Posts: 5279
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post by Lutz »

'exists' always returns the element that meets the condition. In case of 'nil', there is an ambiguity how to interpret the result. BTW R6RS-5.92 defines it the same way, but they don't say anything about this case, and the Schemes I have installed don't have 'exists'.

I think, letting 'exists' only return 'nil' or 'true' instead of the element which mets the condition, would defeat the whole purpose of 'exists'.

It will stay the way its is, but I will mention this ambiguity and how to work around it in the documentation.

In most usage cases of 'exits', we will not look for 'nil' but for something else, if we want to look for 'nil', then 'index' must be used.

Post Reply