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

Re: chained comparisons

Thread Previous | Thread Next
From:
ilmari
Date:
April 27, 2020 11:36
Subject:
Re: chained comparisons
Message ID:
874kt5tbd2.fsf@wibble.ilmari.org
David Nicol <davidnicol@gmail.com> writes:

> if middleval is a function, does it get called twice or is the result
> cached?
>
> if ($lower <= ( sub {$tiedthing})->() <= $upper ) { # a monad with a gonad

The confusion here seems to be between expression evaluation and value
reading (e.g. GET magic, FETCH for tied values).  The expression gets
evaluated once, the resulting value may get read multiple times.

- ilmari

> On Thu, Apr 9, 2020 at 6:17 AM Sawyer X <xsawyerx@gmail.com> wrote:
>
>> Honestly, I think this is the best compromise.
>>
>>
>>
>> On 4/8/20 7:11 PM, David Nicol wrote:
>> >
>> >
>> > so document this and recommend making local copies of the fetched
>> > values from expensive tied variables, at least for now
>> >
>> >
>> > my $middleval = $tiedthing;
>> > if ($lowerbound < $middleval < $upperval) { ...
>> >
>> >
>> >     . All users see is that a tied variable is being evaluated twice.
>> >
>> >
>> >
>> > --
>> > "I know Darth Vader's really got you annoyed
>> >  but remember if you kill him then you'll be unemployed" -- Alfred M.
>> > Yankovic
>>

-- 
- Twitter seems more influential [than blogs] in the 'gets reported in
  the mainstream press' sense at least.               - Matt McLeod
- That'd be because the content of a tweet is easier to condense down
  to a mainstream media article.                      - Calle Dybedahl

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