Skip to content

Instantly share code, notes, and snippets.

@Mon-Ouie
Created November 25, 2011 15:58
Show Gist options
  • Save Mon-Ouie/1393862 to your computer and use it in GitHub Desktop.
Save Mon-Ouie/1393862 to your computer and use it in GitHub Desktop.
SmallInt => # self becomes SmallInt
define multiply_by: n and_add: stuff
self * n + stuff
Foo := Object subclass => # (=> has a very low precedence)
define love # love is an odd, little thing.
3
Block =>
define call
self call: []
True =>
# for true, call the block passed as the if_true: argument
define if_true: a if_false: b
a call
define if_false: a if_true: b
b call
define if_true: block
block call
define if_false: block
nil
define or: other
self
define and: other
other call
define not
false
False =>
# for false objects, call the block passed as the if_false: argument
define if_true: a if_false: b
b call
define if_false: a if_true: b
a call
define if_true: block
nil
define if_false: block
block call
define or: other
other call
define and: other
self
define not
true
SmallInt =>
define factorial
(self = 0) if_true: {1} # if self is 0, return 1
if_false: { self * (self - 1) factorial } # otherwise, return n * (n-1)!
self test: 10 factorial; # (test: is a method to print object, until I get a real IO class)
a_var := 3
z := (x, y) { x + y } call: [1, 2]; # create a block inline and call it with 1 and 2
[1, 2, 3, 4] do: (n) { self test: z + n } # call this block for each element. Notice z gets captured, but not other local variables.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment