diff options
author | Russell Allen <mail@russell-allen.com> | 2014-10-27 22:13:08 +1100 |
---|---|---|
committer | Russell Allen <mail@russell-allen.com> | 2014-10-27 22:13:08 +1100 |
commit | 9fdfb3f56627c23b5dc5581fef353e010e7ff148 (patch) | |
tree | d360a0f82405d0d52c68797bb2cd0fd51a71b0d7 /self.html.markdown | |
parent | 3c66f479413af0f7d00de8e46ec449cac293f4bd (diff) |
Better use of linebreaks
Diffstat (limited to 'self.html.markdown')
-rw-r--r-- | self.html.markdown | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/self.html.markdown b/self.html.markdown index e1a52af8..7b1f38af 100644 --- a/self.html.markdown +++ b/self.html.markdown @@ -83,29 +83,32 @@ Self defines flow control like Smalltalk and Ruby by way of blocks. Blocks are d Examples of the use of a block: ``` -'hello' copyMutable mapBy: [|:c| c capitalize] "returns 'HELLO'" +"returns 'HELLO'" +'hello' copyMutable mapBy: [|:c| c capitalize] -'hello' size > 5 ifTrue: ['Yay'] False: ['Nah'] "returns 'Nah'" +"returns 'Nah'" +'hello' size > 5 ifTrue: ['Yay'] False: ['Nah'] +"returns 'HaLLO'" 'hello' copyMutable mapBy: [|:c| c = 'e' ifTrue: [c capitalize] False: ['a']] -"returns 'HaLLO'" ``` Multiple expressions are separated by a period. ^ returns immediately. ``` +"returns An 'E'! How icky!" 'hello' copyMutable mapBy: [|:c. tmp <- ''| tmp: c capitalize. tmp = 'E' ifTrue: [^ 'An \'E\'! How icky!']. c capitalize ] -"returns An 'E'! How icky!" ``` Blocks are performed by sending them the message 'value' and inherit (delegate to) their contexts: ``` +"returns 0" [|x| x: 15. "Repeatedly sends 'value' to the first block while the result of sending 'value' to the @@ -113,7 +116,6 @@ Blocks are performed by sending them the message 'value' and inherit (delegate t [x > 0] whileTrue: [x: x - 1]. x ] value -"returns 0" ``` # Methods @@ -121,14 +123,16 @@ Blocks are performed by sending them the message 'value' and inherit (delegate t Methods are like blocks but are not within a context but are the values of slots. Unlike Smalltalk, methods by default return their final value not 'self'. ``` -"Here is an object with one assignable slot 'x' and a method 'reduceXTo: y'" +"Here is an object with one assignable slot 'x' and a method 'reduceXTo: y'. +Sending the message 'reduceXTo: 10' to this object will put +the object '10' in the 'x' slot and return the original object" (| x <- 50. reduceXTo: y = ( [x > y] whileTrue: [x: x - 1]. self) |) -"Sending the message 'reduceXTo: 10' to this object will put the object '10' in the 'x' slot and return the original object" +. ``` # Prototypes |