Re: = vs := and = vs ==

new topic     » goto parent     » topic index » view thread      » older message » newer message

The reason this is clear in Euphoria is because you can't do assignments within expressions unlike certain languages. In some languages (like C), assignment statements are expressions in themselves, and return a value. Therefore, the meaning of assignment vs. comparison is ambiguous.

In Euphoria, this isn't the case. Assignment is one kind of statement which must start with an identifier followed by '=' followed by an expression. There is no ambiguity because assignment statements cannot be part of an expression; they don't return a value.

One problem is that in cases involving sequences, comparison operators return a value other than "true" or "false" in Euphoria. That was a design mistake, in my view.

I've been playing around with ideas and I know that it has been hashed out before.

All comparison operators should return a "true" or "false" value of 1 or 0.

If I was designing a Euphoria-like language, here's how I would handle operators:

where op is a mathematical operation + - * / 
Sequence op scalar or scalar op sequence = new sequence with operation applied. (This is how Euphoria acts now). 
sequence op sequence = new sequence with all elements opped together. 
Mismatched sequence size is a no op for elements of the longer sequence [even for - and /]. 
{} op object is no op. Returns object unchanged. 
 
where op is a comparison operation = != < > and or 
0 is false. Comparisons return '0' as false. 
{} is false. 
not zero is true. Comparisons return '1' as true. 
Any non-empty sequence is true. 
 
sequence op sequence = boolean value of 1 or 0 (true or false). Comparison is a deep comparison if necessary. 
 
{} op object returns false for all tests except !=. 
{} op {} returns false for all tests except =. 
 

For Euphoria's current comparison behavior, I would use builtins.

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu