[squeak-dev] correct form for Problem With Blocks

gettimothy gettimothy at zoho.com
Sun Feb 14 14:21:55 UTC 2021


Hi Levente,



Thank you for your reply.



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.



I did, it does. thx.



Fwiw, here are the tests I have for this rule ...It might make things clearer on what it is meant to accomplish.  The pattern is borrowed from some Algebraic PEG grammar I found on the net.

The purpose is to support some PHP-isms in the wikitext grammar...basically PHP version of callbacks given a pattern.


testFloat



<timeout: 5 "seconds">



"Float						<-  Multiplicand  (''e'' Multiplicand)+"

| n output actor |



actor := PEGWikiMediaGeneratorTables new.

actor transcripton: false.  "disable tracing to Transcript"



n := '-2.3e-4'.

output := parser parse: 'Negation' stream: n reading actor: actor.

self assert: (output = 	-0.00023 ).



n := '6e2e3'.

output := parser parse: 'Float' stream: n reading actor: actor.

self assert: (output = 600000.0) .





n := '2e3'.

output := parser parse: 'Float' stream: n reading actor: actor.

self assert: (output = 2000) .





n := '-2.3e-4'.

output := parser parse: 'Negation' stream: n reading actor: actor.

self assert: (output = 	-0.00023 ).









n := '(trunc2)e(trunc-3)'.

output := parser parse: 'Float' stream: n reading actor: actor.

self assert: (output = 	0.002) .





n := '(trunc2)e(trunc0)'.

output := parser parse: 'Float' stream: n reading actor: actor.

self assert: (output = 	2) .



n := '(trunc2)e(trunc18)'.

output := parser parse: 'Float' stream: n reading actor: actor. 

self assert: (output = 2.0e18) .



n := '(trunc2)e(trunc19)'.

output := parser parse: 'Float' stream: n reading actor: actor.

self assert: (output = 2.0e19) .



n := '6e(5-2)'.

output := parser parse: 'Float' stream: n reading actor: actor.

self assert: (output = 6000.0) .



n := '(5-2)e-2'.

output := parser parse: 'Float' stream: n reading actor: actor.

self assert: (output = 0.03) .





n := '6e(5-2)e-2'.

output := parser parse: 'Float' stream: n reading actor: actor.

self assert: (output = 60) .





n := '5.0e-324'.  "(Float fmin) * (Float fmax)"

output := parser parse: 'Operation' stream: n reading actor: actor.

self assert: (output = (Float fmin) ) .
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20210214/9addd27f/attachment.html>


More information about the Squeak-dev mailing list