[squeak-dev] correct form for Problem With Blocks
gettimothy
gettimothy at zoho.com
Thu Feb 11 18:41:49 UTC 2021
Hi Folks,
I am importing my grammar/xtreams parsing work into its own image so that I can change my system fonts without making my other projects look funky with the chages.
The base image is:
Image
-----
/home/wm/usr/src/smalltalk/squeak6.0alpha/shared/Squeak6.0alpha-19802-64bit.image
Squeak6.0alpha
latest update: #20147
to the latest:
/home/wm/Squeak/images/WikitextParser/WikitextParser.image
Squeak6.0alpha
latest update: #20188
During the import of my work, I ran into this issue regarding Store Into in a block:
http://forum.world.st/Cuis-problem-with-blocks-td1047783.html#a1049556
The parser is looking for patterns of (10e2)e2....i.e. exponential notation of unknown length, i.e. per the comment on Collection inject: into: accumulate a running value...
Per the email chain referenced, the "Allow block argument assignment" is allowed in the former, and not allowed in the latest, which is cool with me, but...
My question is "what is the generic form" that I can use to duplicate the behaviour I want?
Here is the original method with the bad store into:
Float: first exponent: pairs
<action: 'Float' arguments:#(1 2)>
"Float <- ( Number / Group / Function ) (''e'' ( Number / Group / Function ))+"
|result|
result := pairs inject: first
into: [ :base :pair |
(pair first = 'e')
ifTrue: [
(pair last abs > 1)
ifTrue:[ base := Float readFrom: ((base asString) , 'e', (pair last asString))]
ifFalse:[ base := (base * (10 raisedTo:(pair last) ))]]].
transcripton ifTrue:[Transcript show:'Float ' , (result asFloat); cr. ].
^ result asFloat
Here is my "hack" to fix it , (I create a tmp variable outside the block to use in place of the "base"):
Float: first exponent: pairs
<action: 'Float' arguments:#(1 2)>
"Float <- ( Number / Group / Function ) (''e'' ( Number / Group / Function ))+"
|result tmp|
result := pairs inject: first
into: [ :base :pair |
(pair first = 'e')
ifTrue: [
(pair last abs > 1)
ifTrue:[tmp := base.
tmp := Float readFrom: ((tmp asString) , 'e', (pair last asString))]
tmp := Float readFrom: ((tmp asString) , 'e', (pair last asString)).
tmp]
ifFalse:[tmp := base.
tmp := (tmp * (10 raisedTo:(pair last) ))]]].
tmp := (tmp * (10 raisedTo:(pair last) )).
tmp]]].
transcripton ifTrue:[Transcript show:'Float ' , (result asFloat); cr. ].
^ result asFloat
I got a bad feeling about this one.
Is there a general form for this ?
My brain is a bit foggy from working the graveyard shift so what would be obvious while in normal conditions , is not obvious today.
Thanks for you time.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20210211/bd0be2af/attachment-0001.html>
More information about the Squeak-dev
mailing list
|