Some thoughts on the 'reveal' operator

ping@lfw.org ping@lfw.org
Thu, 23 Sep 1999 22:31:07 -0700 (PDT)


On Thu, 23 Sep 1999, Mark S. Miller wrote:
> The default case should grant the *least authority*, so to speak.

Upon first seeing the "reveal" operator my reaction was like Chip's:
seems a hassle, tricky to read, and a source of much consternation
for the beginning E programmer.  However, the principle of defaulting
to least revelation is indeed a sound one, and when you describe that
you've had personal experience with making the mistake of revealing
too much, it's pretty convincing!

> Of course, a better notation can still be found.

At the very least, i suggest that in all your examples you separate
the "^" from the thing it returns with a space.  For example, in:

    ^n * factorial(n-1)

the carat symbol visually blends with the "n" and appears to be an
operation upon the "n".  Since it looks like an operator, and as an
operator it has very low precedence, it's better to keep it separated.
Compare:

    define factorial(n) {
        ^if (n <= 0) {
            ^1
        } else {
            ^n * factorial(n-1)
        }
    }

    define factorial(n) {
        ^ if (n <= 1) {
            ^ 1
        } else {
            ^ n * factorial(n-1)
        }
    }

(By the way, doesn't E have bitwise xor?  How is it spelled if not "^"?)

As a random thought, "^^" is even more visually distinct, and
doesn't remind the C programmer of "^" for bitwise xor.

    define factorial(n) {
        ^^ if (n <= 1) {
            ^^ 1
        } else {
            ^^ n * factorial(n-1)
        }
    }

(Then again, there are a number of times when i have wished for
^^ to be a logical xor operator.  In C i'd end up doing some
horrible thing like ((a > 5) + (b > 4)) == 1.)

A keyword might still be more appropriate.

    define factorial(n) {
        reveal if (n <= 1) {
            reveal 1
        } else {
            reveal n * factorial(n-1)
        }
    }


-- ?!ng