From b82da4edfe654617b3309f3fba382a13f2565c81 Mon Sep 17 00:00:00 2001 From: Russell Allen Date: Mon, 27 Oct 2014 22:07:24 +1100 Subject: [PATCH 1/8] First draft Self page --- self.html.markdown | 142 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 142 insertions(+) create mode 100644 self.html.markdown diff --git a/self.html.markdown b/self.html.markdown new file mode 100644 index 00000000..bd81285e --- /dev/null +++ b/self.html.markdown @@ -0,0 +1,142 @@ +--- +language: self +contributors:r + - ["Russell Allen", "http://github.com/russellallen"] +filename: self.html.markdown +--- + +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. + +``` +"This is a comment" + +"A string:" +'This is a string with \'escaped\' characters.\n' + +"A 30 bit integer" +23 + +"A 30 bit float" +3.2 + +"-20" +-14r16 + +"An object which only understands one message, 'x' which returns 20" +(| + x = 20. +|) + +"An object which also understands 'x:' which sets the x slot" +(| + x <- 20. +|) + +"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 also sending the message 'true' to the lobby." +(| parent* = traits point. + x = 7. + y <- 5. + isNice = true. +|) +``` + +# 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. + +``` +23 printLine → unary message, sends 'printLine' to the object '23' + which prints the string '23' to stdout and returns the receiving object (ie 23) +(23 + 7) * 8 → sends the message '+' with '7' to '23', then the message '*' with '8' to the result +2 power: 8 → sends 'power:' to '2' with '8' returns 256 +'hello' keyOf: 'e' IfAbsent: -1 → sends 'keyOf:IfAbsent:' to 'hello' with arguments 'e' and '-1'. Returns 1, the index of 'e' in 'hello'. +``` + +# Blocks + +Self defines flow control like Smalltalk and Ruby by way of blocks. Blocks are delayed computations of the form: + +``` +[|:x. localVar| x doSomthing With: localVar] +``` + +Examples of the use of a block: + +``` +'hello' copyMutable mapBy: [|:c| c capitalize] → 'HELLO' + +'hello' size > 5 ifTrue: ['Yay'] False: ['Nah'] → 'Nah' + +'hello' copyMutable mapBy: [|:c| + c = 'e' ifTrue: [c capitalize] + False: ['a']] + → 'HaLLO' +``` + +Multiple expressions are separated by a period. ^ returns immediately. + +``` +'hello' copyMutable mapBy: [|:c. tmp <- ''| + tmp: c capitalize. + tmp = 'E' ifTrue: [^ 'An \'E\'! How icky!']. + c capitalize + ] + → An 'E'! How icky! +``` + +Blocks are performed by sending them the message 'value' and inherit (delegate to) their contexts: +``` +[|x| + 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 +] value → 0 +``` + +# Methods + +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'" +(| + 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 + +Self has no classes. The way to get an object is to find a prototype and copy it. + +``` +| d | +d: dictionary copy. +d at: 'hello' Put: 23 + 8. +d at: 'goodbye' Put: 'No!. +"Prints No!" +( d at: 'goodbye' IfAbsent: 'Yes! ) printLine. +"Prints 31" +( d at: 'hello' IfAbsent: -1 ) printLine. +``` + +# Further information + +The [Self handbook](http://handbook.selflanguage.org) has much more information, and nothing beats hand-on experience with Self by downloading it from the [homepage](http://www.selflanguage.org). From 3c66f479413af0f7d00de8e46ec449cac293f4bd Mon Sep 17 00:00:00 2001 From: Russell Allen Date: Mon, 27 Oct 2014 22:11:20 +1100 Subject: [PATCH 2/8] Cleaner code samples --- self.html.markdown | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/self.html.markdown b/self.html.markdown index bd81285e..e1a52af8 100644 --- a/self.html.markdown +++ b/self.html.markdown @@ -57,11 +57,19 @@ The inbuild Self parser can construct objects, including method 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. ``` -23 printLine → unary message, sends 'printLine' to the object '23' - which prints the string '23' to stdout and returns the receiving object (ie 23) -(23 + 7) * 8 → sends the message '+' with '7' to '23', then the message '*' with '8' to the result -2 power: 8 → sends 'power:' to '2' with '8' returns 256 -'hello' keyOf: 'e' IfAbsent: -1 → sends 'keyOf:IfAbsent:' to 'hello' with arguments 'e' and '-1'. Returns 1, the index of 'e' in 'hello'. +"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 + +"sends 'power:' to '2' with '8' returns 256" +2 power: 8 + +"sends 'keyOf:IfAbsent:' to 'hello' with arguments 'e' and '-1'. +Returns 1, the index of 'e' in 'hello'." +'hello' keyOf: 'e' IfAbsent: -1 ``` # Blocks @@ -75,14 +83,14 @@ 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] → 'HELLO' +'hello' copyMutable mapBy: [|:c| c capitalize] "returns 'HELLO'" -'hello' size > 5 ifTrue: ['Yay'] False: ['Nah'] → 'Nah' +'hello' size > 5 ifTrue: ['Yay'] False: ['Nah'] "returns 'Nah'" 'hello' copyMutable mapBy: [|:c| c = 'e' ifTrue: [c capitalize] False: ['a']] - → 'HaLLO' +"returns 'HaLLO'" ``` Multiple expressions are separated by a period. ^ returns immediately. @@ -93,7 +101,7 @@ Multiple expressions are separated by a period. ^ returns immediately. tmp = 'E' ifTrue: [^ 'An \'E\'! How icky!']. c capitalize ] - → An 'E'! How icky! +"returns An 'E'! How icky!" ``` Blocks are performed by sending them the message 'value' and inherit (delegate to) their contexts: @@ -104,7 +112,8 @@ Blocks are performed by sending them the message 'value' and inherit (delegate t second block is the 'true' object" [x > 0] whileTrue: [x: x - 1]. x -] value → 0 +] value +"returns 0" ``` # Methods From 9fdfb3f56627c23b5dc5581fef353e010e7ff148 Mon Sep 17 00:00:00 2001 From: Russell Allen Date: Mon, 27 Oct 2014 22:13:08 +1100 Subject: [PATCH 3/8] Better use of linebreaks --- self.html.markdown | 18 +++++++++++------- 1 file 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 From 9d9dd467cd836e169d64ff6f24749a7c52865a22 Mon Sep 17 00:00:00 2001 From: Russell Allen Date: Wed, 29 Oct 2014 14:46:27 +1100 Subject: [PATCH 4/8] Fix typos --- self.html.markdown | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/self.html.markdown b/self.html.markdown index 7b1f38af..f4b5fefc 100644 --- a/self.html.markdown +++ b/self.html.markdown @@ -1,6 +1,6 @@ --- language: self -contributors:r +contributors: - ["Russell Allen", "http://github.com/russellallen"] filename: self.html.markdown --- @@ -38,13 +38,19 @@ The inbuild Self parser can construct objects, including method objects. x <- 20. |) -"An object which understands the method 'doubleX' which doubles the value of x and then returns the object" +"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 also sending the message 'true' to the lobby." +"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. y <- 5. @@ -77,7 +83,7 @@ Returns 1, the index of 'e' in 'hello'." Self defines flow control like Smalltalk and Ruby by way of blocks. Blocks are delayed computations of the form: ``` -[|:x. localVar| x doSomthing With: localVar] +[|:x. localVar| x doSomething with: localVar] ``` Examples of the use of a block: @@ -120,7 +126,7 @@ Blocks are performed by sending them the message 'value' and inherit (delegate t # Methods -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'. +Methods are like blocks but they are not within a context but instead are stored as 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'. From 3f69c38ba3594eb93d86d1f4b2456241ffe9b14a Mon Sep 17 00:00:00 2001 From: xk liu Date: Thu, 30 Oct 2014 11:07:40 +0800 Subject: [PATCH 5/8] [matlab/en] Fix block comment syntax. The %{ and %} operators must appear alone on the lines that immediately precede and follow the block of help text. Do not include any other text on these lines. Reference: http://www.mathworks.com/help/matlab/matlab_prog/comments.html --- matlab.html.markdown | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/matlab.html.markdown b/matlab.html.markdown index 121f16de..2b9077d5 100644 --- a/matlab.html.markdown +++ b/matlab.html.markdown @@ -15,10 +15,12 @@ If you have any feedback please feel free to reach me at ```matlab % Comments start with a percent sign. -%{ Multi line comments look +%{ +Multi line comments look something like -this %} +this +%} % commands can span multiple lines, using '...': a = 1 + 2 + ... From 9324987c1fc465379060491d9a4b1c25cffde0fc Mon Sep 17 00:00:00 2001 From: Frederik Ring Date: Thu, 30 Oct 2014 16:43:49 +0100 Subject: [PATCH 6/8] use propernotation for decimals --- javascript.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/javascript.html.markdown b/javascript.html.markdown index 792cab98..a92dcb4a 100644 --- a/javascript.html.markdown +++ b/javascript.html.markdown @@ -46,7 +46,7 @@ doStuff() // Some basic arithmetic works as you'd expect. 1 + 1; // = 2 -.1 + .2; // = 0.30000000000000004 +0.1 + 0.2; // = 0.30000000000000004 8 - 1; // = 7 10 * 2; // = 20 35 / 5; // = 7 From 02e81acfe1dc548553082672a2d04f826a0812e6 Mon Sep 17 00:00:00 2001 From: Adam Bard Date: Fri, 31 Oct 2014 00:44:24 +0200 Subject: [PATCH 7/8] Update self.html.markdown --- self.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/self.html.markdown b/self.html.markdown index f4b5fefc..69524a84 100644 --- a/self.html.markdown +++ b/self.html.markdown @@ -2,7 +2,7 @@ language: self contributors: - ["Russell Allen", "http://github.com/russellallen"] -filename: self.html.markdown +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. From 112b0b7662d3e235e8bee88ba45fccd8d7932e98 Mon Sep 17 00:00:00 2001 From: Wes Turner Date: Thu, 30 Oct 2014 19:46:37 -0500 Subject: [PATCH 8/8] DOC: bash.html.markdown: add bash docs examples --- bash.html.markdown | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/bash.html.markdown b/bash.html.markdown index 11c1f3a2..81d586c4 100644 --- a/bash.html.markdown +++ b/bash.html.markdown @@ -208,4 +208,30 @@ grep "^foo.*bar$" file.txt grep -c "^foo.*bar$" file.txt # if you literally want to search for the string, and not the regex, use fgrep (or grep -F) fgrep "^foo.*bar$" file.txt + + +# Read Bash shell builtins documentation with the bash 'help' builtin: +help +help help +help for +help return +help source +help . + +# Read Bash manpage documentation with man +apropos bash +man 1 bash +man bash + +# Read info documentation with info (? for help) +apropos info | grep '^info.*(' +man info +info info +info 5 info + +# Read bash info documentation: +info bash +info bash 'Bash Features' +info bash 6 +info --apropos bash ```