Skip to content

Instantly share code, notes, and snippets.

@Wilfred
Created August 27, 2017 16:38
Show Gist options
  • Save Wilfred/1efdc86091a02b43b70325a58dbcc507 to your computer and use it in GitHub Desktop.
Save Wilfred/1efdc86091a02b43b70325a58dbcc507 to your computer and use it in GitHub Desktop.
pharo conditionals example
whileMatches: aStream do: aBlock
"Execute block, passing in this instance, for every match in stream.
Be extra careful about successful matches which consume no input.
After those, make sure to advance or finish if already at end."
| wholeMatch reachedEnd |
reachedEnd := false.
[ self searchStream: aStream ]
whileTrue: [ wholeMatch := self subexpression: 1.
wholeMatch size = 0
ifTrue: [ aStream atEnd
ifTrue: [ reachedEnd := true ]
ifFalse: [ aStream next ] ].
reachedEnd
ifTrue: [ ^ self ]
ifFalse: [ aBlock value: self ] ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment