Turning a Blind Eye to Evaluator "Abuse"

I've gotten kind of attached to the current look and behavior of AND and OR, which allow short-circuiting even though one would not think the language could (should?) be able to.

It doesn't require simple variables be in a GROUP! on the right hand side.

>> if true and true [print "True"] else [print "False"]
True

...but a function call has to be.

>> foo: func [x] [
      print "Calling foo!"
      return x > 1000
   ]

>> if false and foo 1020 [print "True!"] else [print "False"]
** Error: words/tuples can't be ACTION! as right hand of OR, AND, XOR

>> if false and (foo 1020) [print "True"] else [print "False"]
False

>> if true and (foo 1020) [print "True!"] else [print "False"]
Calling foo!
True

Note that if the thing to the left of the AND is false, it does not run the code in the GROUP! on the right. This requires that the right hand side be a quoted parameter convention.

Alternatively we could not quote it, and require the right hand side be in a block:

>> if true and [true] [print "True"] else [print "False"]
True

>> if false and [foo 1020] [print "True"] else [print "False"]
False

But I don't like that.

Alternatively we could say we don't offer this and you always use ALL...maybe with COMMA! and maybe not:

>> if all [true true] [print "True"] else [print "False"]
True

>> if all [false, foo 1020] [print "True"] else [print "False"]
False

I just don't think that looks as natural.

It's Like I Said In "Speaking With Tics"...

If you think seeing a GROUP! on the right of AND and OR that doesn't unconditionally evaluate at the callsite is weird, why are you comfortable with for-each x [1 2 3] [...]? That didn't unconditionally evaluate x. Do you expect it to be for-each 'x instead?

It's just too nice to be able to say things like if var1 and var2 or (a > b) [...].

To me, part of what makes the language special is the ability to bend the evaluator to how we want to read code, vs bending code to fit the evaluator. The existence of mechanics like quoted parameters are there to let this happen.

You don't have to use it. And the ability to switch it to where AND is a prefix operator that does bitwise math is the magic of the freedom of choice. You can choose to change the definition even on a module-by-module basis, or on a function-by-function basis.

Further: if you're not bending the language, you're probably not really using it.

2 Likes