summaryrefslogtreecommitdiffhomepage
path: root/self.html.markdown
diff options
context:
space:
mode:
authorSuzane Sant Ana <tetestonaldo@gmail.com>2017-12-31 14:27:06 -0200
committerGitHub <noreply@github.com>2017-12-31 14:27:06 -0200
commit42f9329bb3a028d374d6397991ac48b44064741e (patch)
tree1e75e2b3e122aeb863e3ffa037f6f64c4027fbf8 /self.html.markdown
parente6b77595f2669d66ac7be43c6e6083cbff80a9a7 (diff)
parent70a36c9bd970b928adde06afb2bd69f6ba8e5d5c (diff)
Merge pull request #1 from adambard/master
update
Diffstat (limited to 'self.html.markdown')
-rw-r--r--self.html.markdown44
1 files changed, 22 insertions, 22 deletions
diff --git a/self.html.markdown b/self.html.markdown
index 69524a84..fc7f69db 100644
--- a/self.html.markdown
+++ b/self.html.markdown
@@ -5,13 +5,13 @@ contributors:
filename: learnself.self
---
-Self is a fast prototype based OO language which runs in its own JIT vm. Most development is done through interacting with live objects through a visual development environment called *morphic* with integrated browsers and debugger.
+Self is a fast prototype based OO language which runs in its own JIT vm. Most development is done through interacting with live objects through a visual development environment called *morphic* with integrated browsers and debugger.
Everything in Self is an object. All computation is done by sending messages to objects. Objects in Self can be understood as sets of key-value slots.
# Constructing objects
-The inbuild Self parser can construct objects, including method objects.
+The inbuild Self parser can construct objects, including method objects.
```
"This is a comment"
@@ -38,18 +38,18 @@ The inbuild Self parser can construct objects, including method objects.
x <- 20.
|)
-"An object which understands the method 'doubleX' which
+"An object which understands the method 'doubleX' which
doubles the value of x and then returns the object"
(|
x <- 20.
doubleX = (x: x * 2. self)
|)
-"An object which understands all the messages
-that 'traits point' understands". The parser
-looks up 'traits point' by sending the messages
-'traits' then 'point' to a known object called
-the 'lobby'. It looks up the 'true' object by
+"An object which understands all the messages
+that 'traits point' understands". The parser
+looks up 'traits point' by sending the messages
+'traits' then 'point' to a known object called
+the 'lobby'. It looks up the 'true' object by
also sending the message 'true' to the lobby."
(| parent* = traits point.
x = 7.
@@ -60,22 +60,22 @@ also sending the message 'true' to the lobby."
# Sending messages to objects
-Messages can either be unary, binary or keyword. Precedence is in that order. Unlike Smalltalk, the precedence of binary messages must be specified, and all keywords after the first must start with a capital letter. Messages are separeated from their destination by whitespace.
+Messages can either be unary, binary or keyword. Precedence is in that order. Unlike Smalltalk, the precedence of binary messages must be specified, and all keywords after the first must start with a capital letter. Messages are separated from their destination by whitespace.
```
-"unary message, sends 'printLine' to the object '23'
+"unary message, sends 'printLine' to the object '23'
which prints the string '23' to stdout and returns the receiving object (ie 23)"
23 printLine
"sends the message '+' with '7' to '23', then the message '*' with '8' to the result"
-(23 + 7) * 8
+(23 + 7) * 8
"sends 'power:' to '2' with '8' returns 256"
-2 power: 8
+2 power: 8
-"sends 'keyOf:IfAbsent:' to 'hello' with arguments 'e' and '-1'.
+"sends 'keyOf:IfAbsent:' to 'hello' with arguments 'e' and '-1'.
Returns 1, the index of 'e' in 'hello'."
-'hello' keyOf: 'e' IfAbsent: -1
+'hello' keyOf: 'e' IfAbsent: -1
```
# Blocks
@@ -90,13 +90,13 @@ Examples of the use of a block:
```
"returns 'HELLO'"
-'hello' copyMutable mapBy: [|:c| c capitalize]
+'hello' copyMutable mapBy: [|:c| c capitalize]
"returns 'Nah'"
-'hello' size > 5 ifTrue: ['Yay'] False: ['Nah']
+'hello' size > 5 ifTrue: ['Yay'] False: ['Nah']
"returns 'HaLLO'"
-'hello' copyMutable mapBy: [|:c|
+'hello' copyMutable mapBy: [|:c|
c = 'e' ifTrue: [c capitalize]
False: ['a']]
```
@@ -105,7 +105,7 @@ Multiple expressions are separated by a period. ^ returns immediately.
```
"returns An 'E'! How icky!"
-'hello' copyMutable mapBy: [|:c. tmp <- ''|
+'hello' copyMutable mapBy: [|:c. tmp <- ''|
tmp: c capitalize.
tmp = 'E' ifTrue: [^ 'An \'E\'! How icky!'].
c capitalize
@@ -119,7 +119,7 @@ Blocks are performed by sending them the message 'value' and inherit (delegate t
x: 15.
"Repeatedly sends 'value' to the first block while the result of sending 'value' to the
second block is the 'true' object"
- [x > 0] whileTrue: [x: x - 1].
+ [x > 0] whileTrue: [x: x - 1].
x
] value
```
@@ -130,12 +130,12 @@ Methods are like blocks but they are not within a context but instead are stored
```
"Here is an object with one assignable slot 'x' and a method 'reduceXTo: y'.
-Sending the message 'reduceXTo: 10' to this object will put
+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].
+ [x > y] whileTrue: [x: x - 1].
self)
|)
.