feat: replace all :::dart code fence markers with :::wren in documentation
Add a custom Pygments lexer plug-in for Wren syntax highlighting, update contributing docs with setup instructions for the lexer, and switch every `:::dart` annotation across all doc/site markdown files to `:::wren` so code examples render with the correct language grammar.
This commit is contained in:
@@ -9,7 +9,7 @@ Boolean values. There are two instances, `true` and `false`.
|
||||
|
||||
Returns the logical complement of the value.
|
||||
|
||||
:::dart
|
||||
:::wren
|
||||
System.print(!true) // "false".
|
||||
System.print(!false) // "true".
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ The name of the class.
|
||||
|
||||
The superclass of this class.
|
||||
|
||||
:::dart
|
||||
:::wren
|
||||
class Crustacean {}
|
||||
class Crab is Crustacean {}
|
||||
|
||||
@@ -19,10 +19,10 @@ The superclass of this class.
|
||||
|
||||
A class with no explicit superclass implicitly inherits Object:
|
||||
|
||||
:::dart
|
||||
:::wren
|
||||
System.print(Crustacean.supertype) // "Object".
|
||||
|
||||
Object forms the root of the class hierarchy and has no supertype:
|
||||
|
||||
:::dart
|
||||
:::wren
|
||||
System.print(Object.supertype) // "null".
|
||||
|
||||
@@ -8,7 +8,7 @@ A lightweight coroutine. [Here](../fibers.html) is a gentle introduction.
|
||||
Creates a new fiber that executes `function` in a separate coroutine when the
|
||||
fiber is run. Does not immediately start running the fiber.
|
||||
|
||||
:::dart
|
||||
:::wren
|
||||
var fiber = Fiber.new {
|
||||
System.print("I won't get printed")
|
||||
}
|
||||
@@ -32,7 +32,7 @@ again. If there is still a reference to the suspended fiber, it can be resumed.
|
||||
Pauses the current fiber and transfers control to the parent fiber. "Parent"
|
||||
here means the last fiber that was started using `call` and not `run`.
|
||||
|
||||
:::dart
|
||||
:::wren
|
||||
var fiber = Fiber.new {
|
||||
System.print("Before yield")
|
||||
Fiber.yield()
|
||||
@@ -48,7 +48,7 @@ When resumed, the parent fiber's `call()` method returns `null`.
|
||||
If a yielded fiber is resumed by calling `call()` or `run()` with an argument,
|
||||
`yield()` returns that value.
|
||||
|
||||
:::dart
|
||||
:::wren
|
||||
var fiber = Fiber.new {
|
||||
System.print(Fiber.yield()) // "value"
|
||||
}
|
||||
@@ -63,7 +63,7 @@ If there is no parent fiber to return to, this exits the interpreter. This can
|
||||
be useful to pause execution until the host application wants to resume it
|
||||
later.
|
||||
|
||||
:::dart
|
||||
:::wren
|
||||
Fiber.yield()
|
||||
System.print("this does not get reached")
|
||||
|
||||
@@ -72,7 +72,7 @@ later.
|
||||
Similar to `Fiber.yield` but provides a value to return to the parent fiber's
|
||||
`call`.
|
||||
|
||||
:::dart
|
||||
:::wren
|
||||
var fiber = Fiber.new {
|
||||
Fiber.yield("value")
|
||||
}
|
||||
@@ -85,7 +85,7 @@ Similar to `Fiber.yield` but provides a value to return to the parent fiber's
|
||||
|
||||
Starts or resumes the fiber if it is in a paused state.
|
||||
|
||||
:::dart
|
||||
:::wren
|
||||
var fiber = Fiber.new {
|
||||
System.print("Fiber called")
|
||||
Fiber.yield()
|
||||
@@ -101,7 +101,7 @@ called it.
|
||||
If the called fiber is resuming from a yield, the `yield()` method returns
|
||||
`null` in the called fiber.
|
||||
|
||||
:::dart
|
||||
:::wren
|
||||
var fiber = Fiber.new {
|
||||
System.print(Fiber.yield())
|
||||
}
|
||||
@@ -114,7 +114,7 @@ If the called fiber is resuming from a yield, the `yield()` method returns
|
||||
Invokes the fiber or resumes the fiber if it is in a paused state and sets
|
||||
`value` as the returned value of the fiber's call to `yield`.
|
||||
|
||||
:::dart
|
||||
:::wren
|
||||
var fiber = Fiber.new {
|
||||
System.print(Fiber.yield())
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ function, so this really just returns the argument. It exists mainly to let you
|
||||
create a "bare" function when you don't want to immediately pass it as a [block
|
||||
argument](../functions.html#block-arguments) to some other method.
|
||||
|
||||
:::dart
|
||||
:::wren
|
||||
var fn = Fn.new {
|
||||
System.print("The body")
|
||||
}
|
||||
@@ -24,7 +24,7 @@ It is a runtime error if `function` is not a function.
|
||||
|
||||
The number of arguments the function requires.
|
||||
|
||||
:::dart
|
||||
:::wren
|
||||
System.print(Fn.new {}.arity) // 0.
|
||||
System.print(Fn.new {|a, b, c| a }.arity) // 3.
|
||||
|
||||
@@ -32,7 +32,7 @@ The number of arguments the function requires.
|
||||
|
||||
Invokes the function with the given arguments.
|
||||
|
||||
:::dart
|
||||
:::wren
|
||||
var fn = Fn.new { |arg|
|
||||
System.print(arg)
|
||||
}
|
||||
|
||||
@@ -23,21 +23,21 @@ The number of elements in the list.
|
||||
|
||||
Inserts the `item` at `index` in the list.
|
||||
|
||||
:::dart
|
||||
:::wren
|
||||
var list = ["a", "b", "c", "d"]
|
||||
list.insert(1, "e")
|
||||
System.print(list) // "[a, e, b, c, d]".
|
||||
|
||||
The `index` may be one past the last index in the list to append an element.
|
||||
|
||||
:::dart
|
||||
:::wren
|
||||
var list = ["a", "b", "c"]
|
||||
list.insert(3, "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.
|
||||
|
||||
:::dart
|
||||
:::wren
|
||||
var list = ["a", "b"]
|
||||
list.insert(-1, "d")
|
||||
list.insert(-2, "c")
|
||||
@@ -45,7 +45,7 @@ If `index` is negative, it counts backwards from the end of the list. It bases t
|
||||
|
||||
Returns the inserted item.
|
||||
|
||||
:::dart
|
||||
:::wren
|
||||
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.
|
||||
@@ -61,7 +61,7 @@ Removes the element at `index`. If `index` is negative, it counts backwards
|
||||
from the end of the list where `-1` is the last element. All trailing elements
|
||||
are shifted up to fill in where the removed element was.
|
||||
|
||||
:::dart
|
||||
:::wren
|
||||
var list = ["a", "b", "c", "d"]
|
||||
list.removeAt(1)
|
||||
System.print(list) // "[a, c, d]".
|
||||
@@ -77,7 +77,7 @@ It is a runtime error if the index is not an integer or is out of bounds.
|
||||
Gets the element at `index`. If `index` is negative, it counts backwards from
|
||||
the end of the list where `-1` is the last element.
|
||||
|
||||
:::dart
|
||||
:::wren
|
||||
var list = ["a", "b", "c"]
|
||||
System.print(list[1]) // "b".
|
||||
|
||||
@@ -88,7 +88,7 @@ It is a runtime error if the index is not an integer or is out of bounds.
|
||||
Replaces the element at `index` with `item`. If `index` is negative, it counts
|
||||
backwards from the end of the list where `-1` is the last element.
|
||||
|
||||
:::dart
|
||||
:::wren
|
||||
var list = ["a", "b", "c"]
|
||||
list[1] = "new"
|
||||
System.print(list) // "[a, new, c]".
|
||||
|
||||
@@ -48,7 +48,7 @@ multiple times in the sequence.
|
||||
Gets the value associated with `key` in the map. If `key` is not present in the
|
||||
map, returns `null`.
|
||||
|
||||
:::dart
|
||||
:::wren
|
||||
var map = {"george": "harrison", "ringo": "starr"}
|
||||
System.print(map["ringo"]) // "starr".
|
||||
System.print(map["pete"]) // "null".
|
||||
|
||||
@@ -7,5 +7,5 @@
|
||||
|
||||
Returns `true`, since `null` is considered [false](../control-flow.html#truth).
|
||||
|
||||
:::dart
|
||||
:::wren
|
||||
System.print(!null) // "true".
|
||||
|
||||
@@ -20,7 +20,7 @@ The value of π.
|
||||
|
||||
The absolute value of the number.
|
||||
|
||||
:::dart
|
||||
:::wren
|
||||
-123.abs // 123
|
||||
|
||||
### **acos**
|
||||
@@ -44,7 +44,7 @@ numbers to determine the quadrant of the result.
|
||||
|
||||
Rounds the number up to the nearest integer.
|
||||
|
||||
:::dart
|
||||
:::wren
|
||||
1.5.ceil // 2
|
||||
(-3.2).ceil // -3
|
||||
|
||||
@@ -56,7 +56,7 @@ The cosine of the number.
|
||||
|
||||
Rounds the number down to the nearest integer.
|
||||
|
||||
:::dart
|
||||
:::wren
|
||||
1.5.floor // 1
|
||||
(-3.2).floor // -4
|
||||
|
||||
@@ -82,7 +82,7 @@ The tangent of the number.
|
||||
|
||||
Negates the number.
|
||||
|
||||
:::dart
|
||||
:::wren
|
||||
var a = 123
|
||||
-a // -123
|
||||
|
||||
@@ -130,7 +130,7 @@ It is a runtime error if `other` is not a number.
|
||||
Creates a [Range](core/range.html) representing a consecutive range of numbers
|
||||
from the beginning number to the ending number.
|
||||
|
||||
:::dart
|
||||
:::wren
|
||||
var range = 1.2..3.4
|
||||
System.print(range.min) // 1.2
|
||||
System.print(range.max) // 3.4
|
||||
@@ -141,7 +141,7 @@ from the beginning number to the ending number.
|
||||
Creates a [Range](core/range.html) representing a consecutive range of numbers
|
||||
from the beginning number to the ending number not including the ending number.
|
||||
|
||||
:::dart
|
||||
:::wren
|
||||
var range = 1.2...3.4
|
||||
System.print(range.min) // 1.2
|
||||
System.print(range.max) // 3.4
|
||||
|
||||
@@ -16,7 +16,7 @@ Iterates over the sequence, passing each element to the function `predicate`.
|
||||
If it returns something [false](../control-flow.html#truth), stops iterating
|
||||
and returns the value. Otherwise, returns `true`.
|
||||
|
||||
:::dart
|
||||
:::wren
|
||||
[1, 2, 3].all {|n| n > 2} // False.
|
||||
[1, 2, 3].all {|n| n < 4} // True.
|
||||
|
||||
@@ -28,7 +28,7 @@ Iterates over the sequence, passing each element to the function `predicate`.
|
||||
If it returns something [true](../control-flow.html#truth), stops iterating and
|
||||
returns that value. Otherwise, returns `false`.
|
||||
|
||||
:::dart
|
||||
:::wren
|
||||
[1, 2, 3].any {|n| n < 1} // False.
|
||||
[1, 2, 3].any {|n| n > 2} // True.
|
||||
|
||||
@@ -50,7 +50,7 @@ Returns the number of elements in the sequence that pass the `predicate`.
|
||||
Iterates over the sequence, passing each element to the function `predicate`
|
||||
and counting the number of times the returned value evaluates to `true`.
|
||||
|
||||
:::dart
|
||||
:::wren
|
||||
[1, 2, 3].count {|n| n > 2} // 1.
|
||||
[1, 2, 3].count {|n| n < 4} // 3.
|
||||
|
||||
@@ -58,7 +58,7 @@ and counting the number of times the returned value evaluates to `true`.
|
||||
|
||||
Iterates over the sequence, passing each element to the given `function`.
|
||||
|
||||
:::dart
|
||||
:::wren
|
||||
["one", "two", "three"].each {|word| System.print(word) }
|
||||
|
||||
### **isEmpty**
|
||||
@@ -85,7 +85,7 @@ together into a single string.
|
||||
Creates a new sequence that applies the `transformation` to each element in the
|
||||
original sequence while it is iterated.
|
||||
|
||||
:::dart
|
||||
:::wren
|
||||
var doubles = [1, 2, 3].map {|n| n * 2 }
|
||||
for (n in doubles) {
|
||||
System.print(n) // "2", "4", "6".
|
||||
@@ -101,7 +101,7 @@ changes to the original sequence will be reflected in the mapped sequence.
|
||||
|
||||
To force eager evaluation, just call `.toList` on the result.
|
||||
|
||||
:::dart
|
||||
:::wren
|
||||
var numbers = [1, 2, 3]
|
||||
var doubles = numbers.map {|n| n * 2 }.toList
|
||||
numbers.add(4)
|
||||
@@ -126,7 +126,7 @@ the sequence is empty, returns `seed`.
|
||||
|
||||
Creates a [list](list.html) containing all the elements in the sequence.
|
||||
|
||||
:::dart
|
||||
:::wren
|
||||
(1..3).toList // [1, 2, 3].
|
||||
|
||||
If the sequence is already a list, this creates a copy of it.
|
||||
@@ -139,7 +139,7 @@ that pass the `predicate`.
|
||||
During iteration, each element in the original sequence is passed to the
|
||||
function `predicate`. If it returns `false`, the element is skipped.
|
||||
|
||||
:::dart
|
||||
:::wren
|
||||
var odds = (1..10).where {|n| n % 2 == 1 }
|
||||
for (n in odds) {
|
||||
System.print(n) // "1", "3", "5", "7", "9".
|
||||
@@ -156,7 +156,7 @@ sequence.
|
||||
|
||||
To force eager evaluation, just call `.toList` on the result.
|
||||
|
||||
:::dart
|
||||
:::wren
|
||||
var numbers = [1, 2, 3, 4, 5, 6]
|
||||
var odds = numbers.where {|n| n % 2 == 1 }.toList
|
||||
numbers.add(7)
|
||||
|
||||
@@ -27,14 +27,14 @@ counting them as you go.
|
||||
Because counting code points is relatively slow, the indexes passed to string
|
||||
methods are *byte* offsets, not *code point* offsets. When you do:
|
||||
|
||||
:::dart
|
||||
:::wren
|
||||
someString[3]
|
||||
|
||||
That means "get the code point starting at *byte* three", not "get the third
|
||||
code point in the string". This sounds scary, but keep in mind that the methods
|
||||
on strings *return* byte indexes too. So, for example, this does what you want:
|
||||
|
||||
:::dart
|
||||
:::wren
|
||||
var metalBand = "Fäcëhämmër"
|
||||
var hPosition = metalBand.indexOf("h")
|
||||
System.print(metalBand[hPosition]) // "h"
|
||||
@@ -52,7 +52,7 @@ ignores any UTF-8 encoding and works directly at the byte level.
|
||||
|
||||
Creates a new string containing the UTF-8 encoding of `codePoint`.
|
||||
|
||||
:::dart
|
||||
:::wren
|
||||
String.fromCodePoint(8225) // "‡"
|
||||
|
||||
It is a runtime error if `codePoint` is not an integer between `0` and
|
||||
@@ -67,7 +67,7 @@ the string and ignore any UTF-8 encoding. In addition to the normal sequence
|
||||
methods, the returned object also has a subscript operator that can be used to
|
||||
directly index bytes.
|
||||
|
||||
:::dart
|
||||
:::wren
|
||||
System.print("hello".bytes[1]) // 101, for "e".
|
||||
|
||||
The `count` method on the returned sequence returns the number of bytes in the
|
||||
@@ -81,7 +81,7 @@ code points of the string *as numbers*. Iteration and subscripting work similar
|
||||
to the string itself. The difference is that instead of returning
|
||||
single-character strings, this returns the numeric code point values.
|
||||
|
||||
:::dart
|
||||
:::wren
|
||||
var string = "(ᵔᴥᵔ)"
|
||||
System.print(string.codePoints[0]) // 40, for "(".
|
||||
System.print(string.codePoints[4]) // 7461, for "ᴥ".
|
||||
@@ -89,7 +89,7 @@ single-character strings, this returns the numeric code point values.
|
||||
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`.
|
||||
|
||||
:::dart
|
||||
:::wren
|
||||
var string = "(ᵔᴥᵔ)"
|
||||
System.print(string.codePoints[2]) // -1, in the middle of "ᵔ".
|
||||
|
||||
@@ -126,7 +126,7 @@ It is a runtime error if `search` is not a string.
|
||||
Implements the [iterator protocol](../control-flow.html#the-iterator-protocol)
|
||||
for iterating over the *code points* in the string:
|
||||
|
||||
:::dart
|
||||
:::wren
|
||||
var codePoints = []
|
||||
for (c in "(ᵔᴥᵔ)") {
|
||||
codePoints.add(c)
|
||||
@@ -161,7 +161,7 @@ Check if the string is not equal to `other`.
|
||||
|
||||
Returns a string containing the code point starting at byte `index`.
|
||||
|
||||
:::dart
|
||||
:::wren
|
||||
System.print("ʕ•ᴥ•ʔ"[5]) // "ᴥ".
|
||||
|
||||
Since `ʕ` is two bytes in UTF-8 and `•` is three, the fifth byte points to the
|
||||
@@ -170,7 +170,7 @@ bear's nose.
|
||||
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:
|
||||
|
||||
:::dart
|
||||
:::wren
|
||||
System.print("I ♥ NY"[3]) // One-byte string whose value is 153.
|
||||
|
||||
It is a runtime error if `index` is greater than the number of bytes in the
|
||||
|
||||
@@ -15,7 +15,7 @@ Prints a single newline to the console.
|
||||
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.
|
||||
|
||||
:::dart
|
||||
:::wren
|
||||
System.print("I like bananas") // Prints "I like bananas".
|
||||
|
||||
### System.**printAll**(sequence)
|
||||
@@ -23,7 +23,7 @@ the object is converted to a string by calling `toString` on it.
|
||||
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.
|
||||
|
||||
:::dart
|
||||
:::wren
|
||||
System.printAll([1, [2, 3], 4]) // Prints "1[2, 3]4".
|
||||
|
||||
### System.**write**(object)
|
||||
@@ -31,7 +31,7 @@ at the end. Each element is converted to a string by calling `toString` on it.
|
||||
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.
|
||||
|
||||
:::dart
|
||||
:::wren
|
||||
System.write(4 + 5) // Prints "9".
|
||||
|
||||
In the above example, the result of `4 + 5` is printed, and then the prompt is
|
||||
|
||||
Reference in New Issue
Block a user