Created
August 27, 2017 16:38
-
-
Save Wilfred/1efdc86091a02b43b70325a58dbcc507 to your computer and use it in GitHub Desktop.
pharo conditionals example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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