[Cuis-dev] #valueEnsured return value
Jaromir Matas
mail at jaromir.net
Mon Feb 27 05:04:24 PST 2023
Hi Hernan,
Thanks for your msg. I’m AFK so briefly: At least one critical use of valueEnsured (or [] ensure: aBlock) is in #terminate. We need to make sure the receiver is evaluated even if the process is terminated. Replacing it with #value will show you which test will fail :)
Yes, it may be understood as a mere shortcut as you wrote but I’m thinking it may as well get another semantics, which is: Evaluate the receiver no matter what and return the block’s return value. In terminate I don’t need the return value but in general it may make sense.
Any opinions welcome; although I’m aware this has rather rare use :)
Thanks again,
Jaromir
From: Hernán Wilkinson<mailto:hernan.wilkinson at 10pines.com>
Sent: Monday, February 27, 2023 13:18
To: Discussion of Cuis Smalltalk<mailto:cuis-dev at lists.cuis.st>; Martin McClure<mailto:martin at hand2mouse.com>
Cc: juan at cuis.st<mailto:juan at cuis.st>; Jaromir Matas<mailto:mail at jaromir.net>
Subject: Re: [Cuis-dev] #valueEnsured return value
hmmm I'm not sure it is a good idea because it goes against the expected return value of #ensure:
I mean, #valueEnsured is just a shortcut for [] ensure: [...], and #ensure: returns the return value of evaluating the receiver block, not the parameter block. The receiver block is [] so it should return nil ([] value).
Currently it is not returning nil because it is implemented like this:
[] ensure: self
and it should be:
^[] ensure: self
Now I'm thinking... I do not understand the need for #valueEnsured, why not just send #value to the block? What is the difference?
I see that #ensure: sends the message #valueNoContextSwitch instead of #value, why not sending #valueNoContextSwitch instead of #valueEnsured then?
I see that #valueEnsured was suggested by @Martin McClure<mailto:martin at hand2mouse.com> , Martin, could you explain the need for this message? Thank you!!
And now, because I'm inconsistent (that is, human :-) ), I'm not sure #valueEnsured has to keep the semantics of the return value of #ensure:, it could not if there is a need for what you are suggesting.
Anyway, I'd like to understand why #valueEnsured is needed.
Cheers!
Hernan.
On Sun, Feb 26, 2023 at 8:34 AM Jaromir Matas via Cuis-dev <cuis-dev at lists.cuis.st<mailto:cuis-dev at lists.cuis.st>> wrote:
Hi Juan, all,
I’d expect this example return 1 instead of a block (for general usage); what do you think?
[1] valueEnsured
Enclosed is a suggestion how to make it return 1.
Best,
Jaromir
--
Jaromír Matas
mail at jaromir.net<mailto:mail at jaromir.net>
--
Cuis-dev mailing list
Cuis-dev at lists.cuis.st<mailto:Cuis-dev at lists.cuis.st>
https://lists.cuis.st/mailman/listinfo/cuis-dev
--
Hernán Wilkinson
Agile Software Development, Teaching & Coaching
Phone: +54-011-4893-2057
Twitter: @HernanWilkinson
site: http://www.10Pines.com<http://www.10pines.com/>
Address: Alem 896, Floor 6, Buenos Aires, Argentina
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cuis.st/mailman/archives/cuis-dev/attachments/20230227/2898a1f7/attachment.htm>
More information about the Cuis-dev
mailing list