On Mon, Nov 7, 2016 at 1:38 PM Fleshgrinder <p...@fleshgrinder.com> wrote:

> Hey guys! :)

The first one should definitely be an error since it makes no sense.


Sense be damed ;-) . I'd attribute it to an identity of sorts (if it was to
go all out with comparison chaining).  Yes it makes little sense, in
practice, but the truth of it would be the same.



> The following will also result in an error:
>
> ```
> if (0 < $x < $y < $z)
> ```
>
> We are only extending binary to ternary for <= and <. Of course it does
> not matter whether any part is constant or variable (hence you can
> exchange any and up to all variables in the following example with a
> constant number expression):
>
> ```
> $x <= $y <= $z;
> $x <= $y < $z;
> $x < $y <= $z;
> $x < $y < $z;
> ```
>

I realize that my comment, and question were going a bit off-topic with
going on about the chaining of comparisons, but I'm interested in it more
because I wonder which would be harder to implement.  It would seem to me
that it would be harder to implement a means in which you only allow one
additional layer of comparison, rather than abstract chaining of
comparisons (<, <=, >, >=).  As Andrea noted, python does allow for
arbitrary chains of comparison.  I'm not exactly sure how precedence would
work with comparisons, rather, as I see it the comparison would need to be
expanded such
```
if (0 < $a < $b > 10)
```
would be akin to
```
if (0 < $a && $a < $b && $b > 10)
```

I, of course, am only projecting a potential syntax, and I'm no yacc/ast
aficionado by any metric, but it'd seem to me that it'd be possible to
convert some stack of elements here into a recursive comparison.

--
Dave

Reply via email to