RCR: Comparing multiple values

Hi list,

wouldn’t it be nice to be able to compare multiple values?
for example:
x, y == 1, 2
#equivalent to x == 1 && y == 2

right now you can do
[x, y] == [1, 2]
but IMHO it doesn’t look so nice

Kristof

Kristof Bastiaensen wrote:

wouldn’t it be nice to be able to compare multiple values?
for example:
x, y == 1, 2
#equivalent to x == 1 && y == 2

For me that notation has one drawback: what should happend if
y = 5
and you’ll write
[x, y == 1, 2]
?

Is it an array with three elements
[x, false, 2]
?

or an array with one element which has value of “multiple comaprision”
[false]
?

···


Szymon Drejewicz

Szymon Drejewicz wrote:

Kristof Bastiaensen wrote:

wouldn’t it be nice to be able to compare multiple values?
for example:
x, y == 1, 2
#equivalent to x == 1 && y == 2

For me that notation has one drawback: what should happend if
y = 5
and you’ll write
[x, y == 1, 2]
?

Is it an array with three elements
[x, false, 2]
?

or an array with one element which has value of “multiple comaprision”
[false]
?

Not sure that this shows anything, but the current behavior for =
instead of == is:

[x, y = 1, 2]
=> [0, 1, 2]

So it looks like the array context overrides the parallel assignment?

It’s not a good analogy, though, because == is a method and = is not.

It should be just ‘false’, as expressed in the first message (i.e.
x==1 and 5==2)

I mean, if we consider ‘,’ as an expression that creates a list
object, than 1,2 == could be just some kind of sugar.
But chosing some kind of precedence would probably be impossible, or
wqould break many of the actual behaviours.

···

il Mon, 26 Apr 2004 08:39:26 +0200, Szymon Drejewicz drejewic@wsisiz.edu.pl ha scritto::

Kristof Bastiaensen wrote:

wouldn’t it be nice to be able to compare multiple values?
for example:
x, y == 1, 2
#equivalent to x == 1 && y == 2

For me that notation has one drawback: what should happend if
y = 5
and you’ll write
[x, y == 1, 2]
?

Is it an array with three elements
[x, false, 2]
?

or an array with one element which has value of “multiple comaprision”
[false]
?

For me that notation has one drawback: what should happend if
y = 5
and you’ll write
[x, y == 1, 2]
?

Is it an array with three elements
[x, false, 2]
?

or an array with one element which has value of “multiple comaprision”
[false]
?

That would be a problem indeed. Note that the same aplies
to method calling: foo(a, b == 1, 2)

The expansion of (x, y == 1, 2) should then occur only outside
parameter lists.

It should be just ‘false’, as expressed in the first message (i.e.
x==1 and 5==2)

It surely shouldn’t be false, because that would disable
comparisons inside parameter lists.

I mean, if we consider ‘,’ as an expression that creates a list
object, than 1,2 == could be just some kind of sugar.
But chosing some kind of precedence would probably be impossible, or
wqould break many of the actual behaviours.

I wouldn’t consider ‘,’ as an expression that creates any object,
but rather as a way to pass multiple arguments to methods and
continuations. This is close to the way it actually is in Ruby.

This would be a syntax extension. However (x, y == exp1, exp2)
would be different from (x == exp1 && y == exp2) because it would
evaluate the parameters first, and then compare the results.

Another construct that might be useful:
x, y += 1, 2
#(meaning x += 1; y += 2)

I think the analogy is good enough. Ruby already does some method
reordering on Arithmetic Operators, so why not on this one?

···

On Mon, 26 Apr 2004 15:58:31 +0900, Joel VanderWerf wrote:

Not sure that this shows anything, but the current behavior for =
instead of == is:

[x, y = 1, 2]
=> [0, 1, 2]

So it looks like the array context overrides the parallel assignment?

It’s not a good analogy, though, because == is a method and = is not.