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

Re: chained comparisons

Thread Previous | Thread Next
February 7, 2020 10:37
Re: chained comparisons
Message ID:
On Fri, 7 Feb 2020 at 10:47, Zefram via perl5-porters <> wrote:

> I have expanded the comparison chaining documentation myself, on top of
> a rebased version of the original commit.  See branch zefram/cmpchain
> at <git://>.

Ok, personally I like your version a fair bit, although I worry its still a
bit not dumb enough.  We want these things understandable by someone who
might find "associativity" a bit intimidating (even if technically correct).

I did a version to try to address your feedback in
"zefram/cmpchain_unsquashed" and pushed it now. Overall I favor yours over
mine, but i think there are a few bits in mine that should be merged back
into yours. Can you have a look at 3bf60ee27671f4082214a0e036a56dfcf3bd2305
and see which bits you think should be merged over? Specifically I am
thinking about the part that tries to make it clear that while you can
chain "==" operators together, and you can chain relational operators
together, chaining operators from both sets doesn't do what someone might
guess. Eg:

 A sequence of the above equality operators, such as S<C<"$a == $b ==
 $c">>, performs chained comparisons, in the same manner as described in
 the previous section for relational operators, but equality operators
 do not chain together with relational operators. Thus

     $p < $q < $r == $t < $u < $v

 is equivalent to

     ( $p < $q && $q < $r ) == ( $t < $u && $u < $v)

 and specifically does B<not> check that C<$r == $t>.

ps: Really sorry for messing up the docs, I am just so eager to get this
merged I got carried away a bit. Also, I think the misunderstanding I had
about mixing equality operators with relational operators IMO suggests that
this part of the docs need some tweaking.

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

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About