Style example output and errors in the docs.

This commit is contained in:
Bob Nystrom
2015-10-18 15:56:52 -07:00
parent 2174ff31e7
commit 545a4cbf7e
24 changed files with 203 additions and 166 deletions
+2 -2
View File
@@ -10,8 +10,8 @@ Boolean values. There are two instances, `true` and `false`.
Returns the logical complement of the value.
:::wren
System.print(!true) // "false".
System.print(!false) // "true".
System.print(!true) //> false
System.print(!false) //> true
### toString
+3 -3
View File
@@ -15,14 +15,14 @@ The superclass of this class.
class Crustacean {}
class Crab is Crustacean {}
System.print(Crab.supertype) // "Crustacean".
System.print(Crab.supertype) //> Crustacean
A class with no explicit superclass implicitly inherits Object:
:::wren
System.print(Crustacean.supertype) // "Object".
System.print(Crustacean.supertype) //> Object
Object forms the root of the class hierarchy and has no supertype:
:::wren
System.print(Object.supertype) // "null".
System.print(Object.supertype) //> null
+7 -7
View File
@@ -39,9 +39,9 @@ here means the last fiber that was started using `call` and not `run`.
System.print("After yield")
}
fiber.call() // "Before yield"
System.print("After call") // "After call"
fiber.call() // "After yield"
fiber.call() //> Before yield
System.print("After call") //> After call
fiber.call() //> After yield
When resumed, the parent fiber's `call()` method returns `null`.
@@ -50,7 +50,7 @@ If a yielded fiber is resumed by calling `call()` or `run()` with an argument,
:::wren
var fiber = Fiber.new {
System.print(Fiber.yield()) // "value"
System.print(Fiber.yield()) //> value
}
fiber.call() // Run until the first yield.
@@ -77,7 +77,7 @@ Similar to `Fiber.yield` but provides a value to return to the parent fiber's
Fiber.yield("value")
}
System.print(fiber.call()) // "value"
System.print(fiber.call()) //> value
## Methods
@@ -107,7 +107,7 @@ If the called fiber is resuming from a yield, the `yield()` method returns
}
fiber.call()
fiber.call() // Prints "null".
fiber.call() //> null
### **call**(value)
@@ -120,7 +120,7 @@ Invokes the fiber or resumes the fiber if it is in a paused state and sets
}
fiber.call()
fiber.call("value") // Prints "value".
fiber.call("value") //> value
### **isDone**
+4 -4
View File
@@ -25,8 +25,8 @@ It is a runtime error if `function` is not a function.
The number of arguments the function requires.
:::wren
System.print(Fn.new {}.arity) // 0.
System.print(Fn.new {|a, b, c| a }.arity) // 3.
System.print(Fn.new {}.arity) //> 0
System.print(Fn.new {|a, b, c| a }.arity) //> 3
### **call**(args...)
@@ -34,10 +34,10 @@ Invokes the function with the given arguments.
:::wren
var fn = Fn.new { |arg|
System.print(arg)
System.print(arg) //> Hello world
}
fn.call("Hello world") // Prints "Hello world".
fn.call("Hello world")
It is a runtime error if the number of arguments given is less than the arity
of the function. If more arguments are given than the function's arity they are
+8 -8
View File
@@ -26,14 +26,14 @@ Inserts the `item` at `index` in the list.
:::wren
var list = ["a", "b", "c", "d"]
list.insert(1, "e")
System.print(list) // "[a, e, b, c, d]".
System.print(list) //> [a, e, b, c, d]
The `index` may be one past the last index in the list to append an element.
:::wren
var list = ["a", "b", "c"]
list.insert(3, "d")
System.print(list) // "[a, b, c, d]".
System.print(list) //> [a, b, c, d]
If `index` is negative, it counts backwards from the end of the list. It bases this on the length of the list *after* inserted the element, so that `-1` will append the element, not insert it before the last element.
@@ -41,12 +41,12 @@ If `index` is negative, it counts backwards from the end of the list. It bases t
var list = ["a", "b"]
list.insert(-1, "d")
list.insert(-2, "c")
System.print(list) // "[a, b, c, d]".
System.print(list) //> [a, b, c, d]
Returns the inserted item.
:::wren
System.print(["a", "c"].insert(1, "b")) // "b".
System.print(["a", "c"].insert(1, "b")) //> b
It is a runtime error if the index is not an integer or is out of bounds.
@@ -64,11 +64,11 @@ are shifted up to fill in where the removed element was.
:::wren
var list = ["a", "b", "c", "d"]
list.removeAt(1)
System.print(list) // "[a, c, d]".
System.print(list) //> [a, c, d]
Returns the removed item.
System.print(["a", "b", "c"].removeAt(1)) // "b".
System.print(["a", "b", "c"].removeAt(1)) //> b
It is a runtime error if the index is not an integer or is out of bounds.
@@ -79,7 +79,7 @@ the end of the list where `-1` is the last element.
:::wren
var list = ["a", "b", "c"]
System.print(list[1]) // "b".
System.print(list[1]) //> b
It is a runtime error if the index is not an integer or is out of bounds.
@@ -91,6 +91,6 @@ backwards from the end of the list where `-1` is the last element.
:::wren
var list = ["a", "b", "c"]
list[1] = "new"
System.print(list) // "[a, new, c]".
System.print(list) //> [a, new, c]
It is a runtime error if the index is not an integer or is out of bounds.
+2 -2
View File
@@ -50,8 +50,8 @@ map, returns `null`.
:::wren
var map = {"george": "harrison", "ringo": "starr"}
System.print(map["ringo"]) // "starr".
System.print(map["pete"]) // "null".
System.print(map["ringo"]) //> starr
System.print(map["pete"]) //> null
### **[**key**]=**(value) operator
+1 -1
View File
@@ -8,4 +8,4 @@
Returns `true`, since `null` is considered [false](../control-flow.html#truth).
:::wren
System.print(!null) // "true".
System.print(!null) //> true
+17 -17
View File
@@ -12,7 +12,7 @@ It is a runtime error if `value` is not a string.
### Num.**pi**
The value of π.
The value of π.
## Methods
@@ -21,7 +21,7 @@ The value of π.
The absolute value of the number.
:::wren
-123.abs // 123
System.print(-123.abs) //> 123
### **acos**
@@ -45,8 +45,8 @@ numbers to determine the quadrant of the result.
Rounds the number up to the nearest integer.
:::wren
1.5.ceil // 2
(-3.2).ceil // -3
System.print(1.5.ceil) //> 2
System.print((-3.2).ceil) //> -3
### **cos**
@@ -57,24 +57,24 @@ The cosine of the number.
Rounds the number down to the nearest integer.
:::wren
1.5.floor // 1
(-3.2).floor // -4
System.print(1.5.floor) //> 1
System.print((-3.2).floor) //> -4
### **isInfinity**
Whether the number is positive or negative infinity or not.
:::wren
99999.isInfinity // false
(1/0).isInfinity // true
System.print(99999.isInfinity) //> false
System.print((1/0).isInfinity) //> true
### **isInteger**
Whether the number is an integer or has some fractional component.
:::wren
2.isInteger // true
2.3.isInteger // false
System.print(2.isInteger) //> true
System.print(2.3.isInteger) //> false
### **isNan**
@@ -100,7 +100,7 @@ Negates the number.
:::wren
var a = 123
-a // -123
System.print(-a) //> -123
### **-**(other), **+**(other), **/**(other), **\***(other) operators
@@ -148,9 +148,9 @@ from the beginning number to the ending number.
:::wren
var range = 1.2..3.4
System.print(range.min) // 1.2
System.print(range.max) // 3.4
System.print(range.isInclusive) // true
System.print(range.min) //> 1.2
System.print(range.max) //> 3.4
System.print(range.isInclusive) //> true
### **...**(other) operator
@@ -159,6 +159,6 @@ from the beginning number to the ending number not including the ending number.
:::wren
var range = 1.2...3.4
System.print(range.min) // 1.2
System.print(range.max) // 3.4
System.print(range.isInclusive) // false
System.print(range.min) //> 1.2
System.print(range.max) //> 3.4
System.print(range.isInclusive) //> false
+10 -10
View File
@@ -14,8 +14,8 @@ The starting point of the range. A range may be backwards, so this can be
greater than [to].
:::wren
(3..5).min // 3.
(4..2).min // 4.
System.print((3..5).min) //> 3
System.print((4..2).min) //> 4
### **to**
@@ -23,8 +23,8 @@ The endpoint of the range. If the range is inclusive, this value is included,
otherwise it is not.
:::wren
(3..5).min // 5.
(4..2).min // 2.
System.print((3..5).min) //> 5
System.print((4..2).min) //> 2
### **min**
@@ -32,8 +32,8 @@ The minimum bound of the range. Returns either `from`, or `to`, whichever is
lower.
:::wren
(3..5).min // 3.
(4..2).min // 2.
System.print((3..5).min) //> 3
System.print((4..2).min) //> 2
### **max**
@@ -41,16 +41,16 @@ The maximum bound of the range. Returns either `from`, or `to`, whichever is
greater.
:::wren
(3..5).min // 5.
(4..2).min // 4.
System.print((3..5).min) //> 5
System.print((4..2).min) //> 4
### **isInclusive**
Whether or not the range includes `to`. (`from` is always included.)
:::wren
(3..5).isInclusive // true.
(3...5).isInclusive // false.
System.print((3..5).isInclusive) //> true
System.print((3...5).isInclusive) //> false
### **iterate**(iterator), **iteratorValue**(iterator)
+16 -12
View File
@@ -17,8 +17,8 @@ If it returns something [false](../control-flow.html#truth), stops iterating
and returns the value. Otherwise, returns `true`.
:::wren
[1, 2, 3].all {|n| n > 2} // False.
[1, 2, 3].all {|n| n < 4} // True.
System.print([1, 2, 3].all {|n| n > 2}) //> false
System.print([1, 2, 3].all {|n| n < 4}) //> true
### **any**(predicate)
@@ -29,8 +29,8 @@ If it returns something [true](../control-flow.html#truth), stops iterating and
returns that value. Otherwise, returns `false`.
:::wren
[1, 2, 3].any {|n| n < 1} // False.
[1, 2, 3].any {|n| n > 2} // True.
System.print([1, 2, 3].any {|n| n < 1}) //> false
System.print([1, 2, 3].any {|n| n > 2}) //> true
### **contains**(element)
@@ -51,8 +51,8 @@ Iterates over the sequence, passing each element to the function `predicate`
and counting the number of times the returned value evaluates to `true`.
:::wren
[1, 2, 3].count {|n| n > 2} // 1.
[1, 2, 3].count {|n| n < 4} // 3.
System.print([1, 2, 3].count {|n| n > 2}) //> 1
System.print([1, 2, 3].count {|n| n < 4}) //> 3
### **each**(function)
@@ -88,7 +88,9 @@ original sequence while it is iterated.
:::wren
var doubles = [1, 2, 3].map {|n| n * 2 }
for (n in doubles) {
System.print(n) // "2", "4", "6".
System.print(n) //> 2
//> 4
//> 6
}
The returned sequence is *lazy*. It only applies the mapping when you iterate
@@ -105,7 +107,7 @@ To force eager evaluation, just call `.toList` on the result.
var numbers = [1, 2, 3]
var doubles = numbers.map {|n| n * 2 }.toList
numbers.add(4)
System.print(doubles) // [2, 4, 6].
System.print(doubles) //> [2, 4, 6]
### **reduce**(function)
@@ -127,7 +129,7 @@ the sequence is empty, returns `seed`.
Creates a [list](list.html) containing all the elements in the sequence.
:::wren
(1..3).toList // [1, 2, 3].
System.print((1..3).toList) //> [1, 2, 3]
If the sequence is already a list, this creates a copy of it.
@@ -140,9 +142,11 @@ During iteration, each element in the original sequence is passed to the
function `predicate`. If it returns `false`, the element is skipped.
:::wren
var odds = (1..10).where {|n| n % 2 == 1 }
var odds = (1..6).where {|n| n % 2 == 1 }
for (n in odds) {
System.print(n) // "1", "3", "5", "7", "9".
System.print(n) //> 1
//> 3
//> 5
}
The returned sequence is *lazy*. It only applies the filtering when you iterate
@@ -160,4 +164,4 @@ To force eager evaluation, just call `.toList` on the result.
var numbers = [1, 2, 3, 4, 5, 6]
var odds = numbers.where {|n| n % 2 == 1 }.toList
numbers.add(7)
System.print(odds) // [1, 3, 5].
System.print(odds) //> [1, 3, 5]
+9 -9
View File
@@ -37,7 +37,7 @@ on strings *return* byte indexes too. So, for example, this does what you want:
:::wren
var metalBand = "Fäcëhämmër"
var hPosition = metalBand.indexOf("h")
System.print(metalBand[hPosition]) // "h"
System.print(metalBand[hPosition]) //> h
If you want to work with a string as a sequence numeric code points, call the
`codePoints` getter. It returns a [Sequence](sequence.html) that decodes UTF-8
@@ -53,7 +53,7 @@ ignores any UTF-8 encoding and works directly at the byte level.
Creates a new string containing the UTF-8 encoding of `codePoint`.
:::wren
String.fromCodePoint(8225) // "‡"
String.fromCodePoint(8225) //> ‡
It is a runtime error if `codePoint` is not an integer between `0` and
`0x10ffff`, inclusive.
@@ -68,7 +68,7 @@ methods, the returned object also has a subscript operator that can be used to
directly index bytes.
:::wren
System.print("hello".bytes[1]) // 101, for "e".
System.print("hello".bytes[1]) //> 101 (for "e")
The `count` method on the returned sequence returns the number of bytes in the
string. Unlike `count` on the string itself, it does not have to iterate over
@@ -83,15 +83,15 @@ single-character strings, this returns the numeric code point values.
:::wren
var string = "(ᵔᴥᵔ)"
System.print(string.codePoints[0]) // 40, for "(".
System.print(string.codePoints[4]) // 7461, for "ᴥ".
System.print(string.codePoints[0]) //> 40 (for "(")
System.print(string.codePoints[4]) //> 7461 (for "ᴥ")
If the byte at `index` does not begin a valid UTF-8 sequence, or the end of the
string is reached before the sequence is complete, returns `-1`.
:::wren
var string = "(ᵔᴥᵔ)"
System.print(string.codePoints[2]) // -1, in the middle of "ᵔ".
System.print(string.codePoints[2]) //> -1 (in the middle of "ᵔ")
### **contains**(other)
@@ -132,7 +132,7 @@ for iterating over the *code points* in the string:
codePoints.add(c)
}
System.print(codePoints) // ["(", "ᵔ", "ᴥ", "ᵔ", ")"].
System.print(codePoints) //> [(, ᵔ, ᴥ, ᵔ, )]
If the string contains any bytes that are not valid UTF-8, this iterates over
those too, one byte at a time.
@@ -162,7 +162,7 @@ Check if the string is not equal to `other`.
Returns a string containing the code point starting at byte `index`.
:::wren
System.print("ʕ•ᴥ•ʔ"[5]) // "ᴥ".
System.print("ʕ•ᴥ•ʔ"[5]) //> ᴥ
Since `ʕ` is two bytes in UTF-8 and `•` is three, the fifth byte points to the
bear's nose.
@@ -171,7 +171,7 @@ If `index` points into the middle of a UTF-8 sequence or at otherwise invalid
UTF-8, this returns a one-byte string containing the byte at that index:
:::wren
System.print("I ♥ NY"[3]) // One-byte string whose value is 153.
System.print("I ♥ NY"[3]) //> (one-byte string [153])
It is a runtime error if `index` is greater than the number of bytes in the
string.
+3 -3
View File
@@ -16,7 +16,7 @@ Prints [object] to the console followed by a newline. If not already a string,
the object is converted to a string by calling `toString` on it.
:::wren
System.print("I like bananas") // Prints "I like bananas".
System.print("I like bananas") //> I like bananas
### System.**printAll**(sequence)
@@ -24,7 +24,7 @@ Iterates over [sequence] and prints each element, then prints a single newline
at the end. Each element is converted to a string by calling `toString` on it.
:::wren
System.printAll([1, [2, 3], 4]) // Prints "1[2, 3]4".
System.printAll([1, [2, 3], 4]) //> 1[2, 3]4
### System.**write**(object)
@@ -32,7 +32,7 @@ Prints a single value to the console, but does not print a newline character
afterwards. Converts the value to a string by calling `toString` on it.
:::wren
System.write(4 + 5) // Prints "9".
System.write(4 + 5) //> 9
In the above example, the result of `4 + 5` is printed, and then the prompt is
printed on the same line because no newline character was printed afterwards.