On Thu, Jan 23, 2014 at 7:59 AM, Eric Wald <[email protected]> wrote:

> I once used a language with three operators:
>
>   left := right   assigned,
>   left == right   compared,
>   left = right    guessed.
>
> The guess was generally correct; when used as a statement, it would
> assign; when used as an expression, it would compare.  Even
> daisy-chained assignments worked properly.  But when you really wanted
> to assign in the condition of a while loop, or assign the result of a
> comparison, you had the option to use the more explicit operators.
>
> Why don't more languages do that?

I think that := and == are good, but the third option strikes me as a
bad idea.  While inference can work pretty well thanks to the
lvalue/rvalue distinction I mentioned earlier, the cost of failure
here is pretty significant and I think the conflation of assignment
with equality is unfortunate in general.  I am on board with
overloading syntax to do the *same* fundamental operation on various
types, but I think that overloading to do entirely different things is
a recipe for confusion and mistakes, even if (and possibly
*especially* if) the compiler can usually figure out what you meant.
I recognize, though, that opinions differ on this.  Larry Wall
especially seems to be a prominent fan of highly implicit, ambiguous,
and idiomatic language syntax.

I can imagine using = to do unification of terms, which might appear
to the end-user who is not familiar with the semantics of the language
to be a sort of assignment/comparison guess, but it's really an
entirely different sort of operation than straight-up assignment or
equality checking.  Unification is the operation that's behind things
like pattern-matching expressions in functional languges and also
behind most of the syntax in logic languages like Prolog.

       --Levi

/*
PLUG: http://plug.org, #utah on irc.freenode.net
Unsubscribe: http://plug.org/mailman/options/plug
Don't fear the penguin.
*/

Reply via email to