develooper Front page | perl.perl5.porters | Postings from February 2020

Re: chained comparisons

Thread Previous | Thread Next
From:
demerphq
Date:
February 7, 2020 09:11
Subject:
Re: chained comparisons
Message ID:
CANgJU+We5T0_k7gzebhJmoGeudK-Y7M3CFca8LOvceW__KMVjg@mail.gmail.com
On Fri, 7 Feb 2020 at 09:59, Zefram via perl5-porters <
perl5-porters@perl.org> wrote:

> demerphq wrote:
> >Er, then my bad. What did I mess up?
>
> You show "<" chaining with "==".  They're at different precedence levels,
> so don't chain together.  "$a < $b == $c" is already legal Perl, meaning
> "($a < $b) == $c".  I think the intent (in C, where this precedence comes
> from) is that the equality operators can function as logical connectives
> EQV and XOR.
>

OH! Definitely my bad. Ok, I will remove the part about '=='.


>
> The bit about FETCH methods is unclear and possibly wrong.  It's firstly
> confusing because it's mixed up with an example concerning an explicit
> call to an expensive function, which is a different kind of expensive
> computation.


Ok, then I misunderstood what you meant by saying they were evaluate only
once.


> The real unclarity is that it doesn't say in which version
> of the code the FETCH method would be called only once.  The ordering of
> the text seems to imply that the chained version would call it only once
> and the unchained version with explicit temporary would call it twice.
> In fact the reality is the reverse: the chained version may call FETCH
> twice (it's done by each comparison op), but the unchained version with
> explicit temporary calls FETCH exactly once (at the assignment to the
> temporary).
>

Oh, ok, that is kinda confusing. Can it be made to call it once?


>
> There's also a typo "exmaple".
>

I don't see an "exmaple" in the version that was in
zefram/cmpchain_squashed. I think there was one in my original text, but I
fixed it after smylers pointed it out.

git grep -i 'exmaple' pod/perlop.pod

doesn't return anything.


>
> Stylistically, if the discussion of chaining is to be so extensive then
> I think it doesn't belong in the section on the relational operators.
> It should instead go with the general discussion of associativity.
>

Hrm, ok, I will see what I can do.  I guess a reference from one place to
the other would make sense.

Yves

-- 
perl -Mre=debug -e "/just|another|perl|hacker/"

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About