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

Re: chained comparisons

Thread Previous | Thread Next
Zefram via perl5-porters
April 8, 2020 05:48
Re: chained comparisons
Message ID:
Tomasz Konojacki wrote:
>This makes sense from the internals POV but it's a very surprising
>behavior from the user's POV.

Only if the user has an already-inaccurate mental model, since overloaded
comparison can easily result in similar multiple fetching.  (See my
reply to Tony.)  Admittedly, poor understanding of this is probably
quite widespread.

>                              The concept of magic doesn't exist on the
>language level,

The concept of fetching the value of a tied variable does exist as an
event that's visible to the user, and there's no problem in referring
to it in documentation.

>All they see is that a tied variable is being evaluated twice.

It's somewhat inaccurate, at least misleading, to refer to this as
"evaluation".  The thing that happens twice here is quite distinct
from the regular evaluation process that eagerly resolves expressions.
The distinction is already very visible at the language level: when
calling a subroutine the argument expression is evaluated (in the strict
sense) exactly once, before the subroutine is called, but the argument
value may be fetched zero, one, or more times, always during execution
of the subroutine.


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