Should Void be Offered to Predicates (for REDUCE, ANY/ALL, etc.)

There's an option to pass a function to some things, to help avoid needing to write the basic logic of the function over again if you just want some difference. So if you want a negating version of ANY you can say:

>> any/predicate [1 + 2 null 3 + 4] :not
== ~null~  ; isotope (decays to null)

There you have a negated form of ANY. You could specialize that:

>> any-not: specialize :any [predicate: :not]
== #[action! {any-not} [block]]

>> any-not [1 + 2 null 3 + 4] then [print "Look, it worked!"]
Look, it worked!

It works with THEN and ELSE thanks to isotopes: a negating form of ANY that returns you an indicator of what the false thing was, while still being able to let you run a THEN or ELSE clause that has the expected semantics. So even though the thing that triggered the short circuit was a NULL, the isotope form was returned and allowed to run the THEN.

But what if there's a void entry, should your predicate function find out about it?

>> reduce/predicate [1 + 2 3 + 4] func [x] [return x * 10]
== [30 70]

>> reduce [1 + 2 if false [<a>] 3 + 4]
== [3 7]

>> reduce/predicate [1 + 2 if false [<a>] 3 + 4] func [x] [return x * 10]
; ...???...

Given that the whole point of predicates is to reuse the work of the core function, it would seem like one of those pieces of work is filtering out the void expressions.

So I think it's pretty clear the above should be == [30 70] with no error given.

But what if the function's argument was ^META? Does that change things?

>> reduce/predicate [1 + 2 if false [<a>] 3 + 4] func [^x] [...]
; ...???...

Or does it have to explicitly say by contract it is interested in voids?

>> reduce/predicate [1 + 2 if false [<a>] 3 + 4] func [^x [<void> any-value!]] [...]
; ...???...

It's a pretty fringe feature either way. I think that in REDUCE's case, we can say that if you really want to get control of every expression...then using REDUCE-EACH with ^META seems a bit more explicit that you want EACH.

I'm going to say for the moment that the predicate in REDUCE, ANY, and ALL will never be offered voids...and that's just part of the benefit of reusing the work.

1 Like