make (a < b < c) illegal?

Henning Hasemann hhasemann at web.de
Thu Feb 15 04:57:43 PST 2007


On Thu, 8 Feb 2007 09:49:56 +0100
Henning Hasemann <hhasemann at web.de> wrote:

> 
> Another way to solve this problem might be the following:
> 
> - Say Comparsion operators are not defined for booleans
> - Instead define a few new operations on booleans such as
>   Aequivalence (for example "<->" instead of "==").
>   Note for example that xor (is it ^^ in D too?) already has
>   the same meaning as != for booleans.
> 
> implications whould be:
> - new operator symbols may have to be introduced
> - this change might break some code, but the compiler
>   should spot every line thats affected by the change
> - it should lead to a much 'cleaner' grammar, think of
>   the reason why its "hello " ~ "world" not "hello " + "world"!
> 

If I remember correctly this is also what eiffel does btw,
AND it whould be possible to realize additionally to the chaining.
see:

a < b < c means (a < b) && (b < c)
a == b == c == d means (a == b) && (b == c) && (c == d)

if you whould want to test if a == b yields the same boolean value as c == d,
i.e. (a == b) == (c == d)
you would write

(a == b) <-> (c == d)

note how clear this reads, you see at a first glance that results
of boolean expressions are compared, which, as it is not used very often
can not happen by accident (as up to now in a < b < c) anymore.

I'm not that sure if the <-> - Symbol is a good idea though, but
Im sure it whould be possible to find alternatives to it.

Henning






More information about the Digitalmars-d mailing list