[squeak-dev] Basic Coding question, I do not recall seeing addressed in the literature
gettimothy
gettimothy at zoho.com
Sat Oct 24 10:31:55 UTC 2020
Hi Folks,
Pardon the noobish "eyes of wonder" on the following.
Recently, Eliot asked...
what is the value of
{ (Float infinity basicAt: 1) hex.
(Float infinity basicAt: 2) hex.
(BoxedFloat64 infinity basicAt: 1) hex.
(BoxedFloat64 infinity basicAt: 2) hex.
BoxedFloat64 infinity == Float infinity }
The result is:
#('16r7FF00000' '16r0' '16r7FF00000' '16r0' true)
This shows that the stuff in an Array is evaluated BEFORE the array is "produced".
This is NOT in the Terse Guide and I do not recall seeing it in the books I read when I first started Squeak.
It is a very handy tool.
I guess the behavior makes sense, as an Array is not a Block . Also, putting the same stuff in an OrderedCollection gives the same behavior.
|x|
x := OrderedCollection new.
x add:(Float infinity basicAt: 1) hex.
x add:(Float infinity basicAt: 2) hex.
x add:(BoxedFloat64 infinity basicAt: 1) hex.
x add:(BoxedFloat64 infinity basicAt: 2) hex.
x add: BoxedFloat64 infinity == Float infinity .
x inspect.
The construct is very reminiscent of on of the early lessons in the SICP series,
Anyhoo, one more cool thing to add to the toolbox.
cheers.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20201024/75e11467/attachment.html>
More information about the Squeak-dev
mailing list
|