roxen.lists.pike.general

Subject Author Date
Re: Pike & Python Martin Stjernholm <mast[at]lysator[dot]liu[dot]se> 12-12-2008
Dave Walton <<dw-pike[at]digger.net>> wrote:

>>   if (`< (0, x, 10)) ...
>> 
>> Looks a bit uglier, tho.
>> 
>
> Oh, cool.  Not nearly as intuitive for the casual reader, though.

I agree. The reason a < b < c doesn't work is that it isn't compatible
(it gets parsed like (a < b) < c). The places where one wants
(a < b) < c and has decided to leave out the parens ought to be
extremely few though, so if we introduce a warning for that then
someday down the road I think we could change it.

One tricky thing though is that we'd need a new calling convention for
cases like a < b <= c; neither `< (a, b, c), `<= (a, b, c), nor
`<= (`< (a, b), c) would work. Hmm, the compiler would probably
rewrite it to (`< (a, bv) && `<= (bv, c)), where bv is the value from
b (since b should only be evaluated once).

> That brings up something I've been wondering...  Why is it that all the
> operators are also functions?  I'm curious what inspired that design.

I don't know for sure, but I guess it stemmed from adding the
possibility to overload operators for objects: For that a function
form was necessary for the declarations, and then of course those
function forms can be used directly in calls as well.

Then things like `< (0, x, 10) were just extensions for more than two
arguments that could be thrown in without disturbing things.

With the reservation that my C++ is very rusty nowadays, I think it's
the same thing there. Only difference is that you write them like
"operator +", while Pike is a bit more brief with "`+" (and it's more
similar to an identifier, which I like).