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.
Hi Tim,
On Thu, 11 Feb 2021, gettimothy via Squeak-dev wrote:
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) ))]]].
That makes no sense. I can't even fathom how it works. #inject:into:'s second argument, the block, must return the computed value. Currently that block returns the value assigned to base when pair first = 'e' and nil otherwise. So, if it works correctly now, which is doubtful, then just remove the assignments to base from the block and it should just work.
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]]].
Those parentheses don't look well balanced, but anyway, there's no need to use tmp, especially not one at the outer scope.
Levente
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.
squeak-dev@lists.squeakfoundation.org