KtTalk

A kotlin library of extension functions that add smalltalk style methods to objects.

Motivation

Smalltalk is a pure OO language in which everything is an object, and everything happens by sending messages(aka method calls). For this reason, it does not have built-in control structures, and you will achieve conditional branches and iterations/loops by calling methods.

For example, if statements in smalltalk are implemented as sending message ifTrue: trueClosure ifFalse: falseClosure to a Boolean object:

220)
ifTrue: [ Transcript show: ’17 x 13 is greater than 220’ ]
// The true block will execute, prints "17 x 13 is greater than 220" on the transcript.
“>

(17 * 13 > 220) 
   ifTrue: [ Transcript show:17 x 13 is greater than 220’ ] 
// The true block will execute, prints "17 x 13 is greater than 220" on the transcript. 

Similarly, sending message whileTrue: block to a closure object achieves something similar to a while loop:

<div class="highlight highlight-source-smalltalk position-relative" data-snippet-clipboard-copy-content="n := 1.
[ n

n := 1. 
[ n < 1000 ] whileTrue: [ n := n*2 ]. 
// n is now 1024.