How ANY and ALL In Other Languages Act on Empty Inputs

I was looking around in the "Red Enhancement Process" repository to see if there was anything there of interest, and one thing that's at least useful was a survey of how other language constructs paralleling ANY and ALL act when given empty inputs.

The repository is BSD-licensed and so I'll reproduce the list here. :stuck_out_tongue:


Red

>> all [] == none
>> any [] == none

Rebol2 & Rebol3:

>> all [] == true
>> any [] == none

Scheme:

(and) #t
(or) #f

Common Lisp:

(and) T
(or) NIL

R:

all() [1] TRUE
any() [1] FALSE

J:

*./>a: 1
+./>a: 0

Julia:

all([]) true
any([]) false

Python:

all([]) True
any([]) False

Javascript:

[].every(function(){}) true
[].some(function(){}) false

Lotsa Precedent For ALL [] Truthy, ANY [] Falsey...

If you squint hard enough, there are legitimate reasons for favoring this choice--if both have to be constrained to just TRUE and FALSE.

The arguments sort of parallel why it's reasonable to say that TRUE > FALSE. But it's sort of abstract...and you wind up talking about "mathematical consensus regarding bounded lattices…more specifically, a complemented distributive lattice."

...BUT...We Can Do Better, With ~VOID~ ISOTOPES!

:man_scientist: :atom_symbol: :microscope:

VOID is the utter absence of value, and I don't think we would want this:

>> expr1: [comment "I'm a comment"]
>> expr2: [elide print "Vanishing!"]

>> x: 10

>> 1 + 2, x: all compose [((expr1)) ((expr2))]
Vanishing
== 3

>> x
== 10

Functions that become truly invisible should be somewhat rare, and do so by contract. Things kind of turn into chaos if you let the property seep too far.

But ~VOID~ ISOTOPES Are Another Thing Altogether

The idea behind a ~void~ isotope is that a function can say that in spirit it produced nothing, but still give back some result... an isotope representation of void intent. You can then work with that, such as to use MAYBE to convert the intent into an actual manifestation of voidness.

So if you are at a callsite and you know that something like an ALL or an ANY might vaporize all of its clauses, you are in the driver's seat to make the call:

>> x: 10

>> 1 + 2, x: all compose [((expr1)) ((expr2))]
== ~void~  ; isotope

>> x: 10

>> 1 + 2 x: maybe all compose [((expr1)) ((expr2))]
== 3  ; or 10, or ~void~ isotope...still thinking about this...

>> x
== 10  ; <-- BUT this is the important bit

I think that the fact ANY [] and ALL [] have kind of eluded a standardized consensus in the Redbol world considers that historically they didn't come up in practice much.

BUT I've got some powerful use cases coming up to demonstrate that take advantage of the ability to erase and MAYBE'-ify the results of ANY and ALL. These use cases blow away any microscopic benefit given by declaring the answers here to be true or false. And for ALL to be truthy it would have to lie in some way--by fabricating an arbitrary truthy value.

You won't have to take my word for it that this is a big win...you'll see for yourself!

:eye: :pig_nose: :eye:

2 Likes