I already thought to use this flow.

but I only wondered if I could use the ^false this way and appearently it is allowed.

so I can begin with this one.

The Pharo track is still hidden but I saw on the github page that in a short time it will be public with some 20 - 25 challenges.

Roelof


Op 4-4-2019 om 14:36 schreef Richard O'Keefe:
For a change this is an exercism problem I know something about.
I did look at the exercism web site, and did all the SML exercises,
but could not find any for Smalltalk or Pharo.

The exercise is in fact about using a stack.
   stack <- empty
   for each character of the string
      if it is one of ( [ { push it on the stack
      if it is one of ) ] }
         if the stack is empty or the top element does not
            correspond to this character, return false
      if it is not one of ( ) [ ] { } just ignore it
   return (the stack is empty)

BOTH of the "return" constructs in this pseudo-code become
^ something
in Smalltalk.  "Long returns", where "^" occurs inside a block,
are well defined, very useful, and universally accepted in Smalltalk.

There is no analogue of "^" for returning from a block.

By the way, this has nothing to do with #do:.  It's about
returning from the method through any number of blocks.
For example, you will sometimes see code like
   x := aDictionary at: aKey ifAbsent: [^false].


On Fri, 5 Apr 2019 at 00:16, Roelof Wobben <r.wob...@home.nl> wrote:
Hello,

For a challenge of Exercism I need to check if some parenthes and
brackets are balanced.

so for example

()  = true
([])  = true

but (])  is not true because the bracket has no opening bracket.

Now I wonder if I can premature end a #do:  like this

collection do: [:element | (condition with element) ifFalse: [^false]]

in pseudo code

is this a valid way to end the do ?
or is there a better way ?

Roelof


Reply via email to