for-all

Q&A's, tips, howto's
Locked
bebalo
Posts: 4
Joined: Mon May 16, 2016 8:27 pm

for-all

Post by bebalo »

> (exists integer? '())
nil
> (exists integer? '(a b 3 t 7))
3
> (for-all integer? '(a b 3 t 7))
nil

Well, that's fine. But what about this:
> (for-all integer? '())
true

Is it intentionally so or have I overlooked something?
-----
My newLISP:
newLISP v.10.7.5 64-bit on Linux IPv4/6 UTF-8 libffi

bebalo
Posts: 4
Joined: Mon May 16, 2016 8:27 pm

Re: for-all

Post by bebalo »

The same holds for float:

> (for-all float? '())
true

Astrobe
Posts: 43
Joined: Mon Jan 11, 2010 9:41 pm

Re: for-all

Post by Astrobe »

It is correct from the perspective of mathematics : the relationship with existential and universal quantification is pretty clear. Math says that (trasposed to newlisp) :

(not (for-all integer? L)) is equivalent to (exists (fn(x) (not (integer? x))) L)

and conversely

(not (exists integer? L)) is equivalent to (for-all (fn(x) (not integer? x))) L)

So once it has been decided that (exists) on an empty list returns nil (which makes sense), (for-all) for an empty list has to return true.

bebalo
Posts: 4
Joined: Mon May 16, 2016 8:27 pm

Re: for-all

Post by bebalo »

Mathematically correct -- good to know. Thank you for your help.

Locked