← Back to context

Comment by vidarh

8 years ago

Compare to Ruby:

    10.times { n = n * 2 }

The latter isn't possible "out of the box", but easy enough to implement:

    class Proc
        def whileTrue; yield while self.call; end
    end

    # And use:
    n = 1
    ->{ n < 10 }.whileTrue { n = n + 1 } 

    puts n

Ruby syntax does get in the way of some of the more succint ways of defining control structures in Smalltalk, but the above shows some of the Smalltalk heritage of Ruby quite well, I think (though, while "10.times" is fairly idiomatic Ruby, implementing constructs like the one below certainly is not).