feat: replace IO class with System class and remove separate IO module
- Delete wren_io.c, wren_io.h, and io.wren source files - Remove multi-arity print overloads and IO.read/IO.time methods - Add System class with print, printAll, write, writeAll methods to core.wren - Update all documentation examples and README to use System.print instead of IO.print
This commit is contained in:
@@ -9,10 +9,9 @@ Boolean values. There are two instances, `true` and `false`.
|
||||
|
||||
Returns the logical complement of the value.
|
||||
|
||||
> !true
|
||||
false
|
||||
> !false
|
||||
true
|
||||
:::dart
|
||||
System.print(!true) // "false".
|
||||
System.print(!false) // "true".
|
||||
|
||||
### toString
|
||||
|
||||
|
||||
@@ -15,14 +15,14 @@ The superclass of this class.
|
||||
class Crustacean {}
|
||||
class Crab is Crustacean {}
|
||||
|
||||
IO.print(Crab.supertype) // "Crustacean"
|
||||
System.print(Crab.supertype) // "Crustacean".
|
||||
|
||||
A class with no explicit superclass implicitly inherits Object:
|
||||
|
||||
:::dart
|
||||
IO.print(Crustacean.supertype) // "Object"
|
||||
System.print(Crustacean.supertype) // "Object".
|
||||
|
||||
Object forms the root of the class hierarchy and has no supertype:
|
||||
|
||||
:::dart
|
||||
IO.print(Object.supertype) // "null"
|
||||
System.print(Object.supertype) // "null".
|
||||
|
||||
@@ -10,7 +10,7 @@ fiber is run. Does not immediately start running the fiber.
|
||||
|
||||
:::dart
|
||||
var fiber = Fiber.new {
|
||||
IO.print("I won't get printed")
|
||||
System.print("I won't get printed")
|
||||
}
|
||||
|
||||
## Static Methods
|
||||
@@ -34,14 +34,14 @@ here means the last fiber that was started using `call` and not `run`.
|
||||
|
||||
:::dart
|
||||
var fiber = Fiber.new {
|
||||
IO.print("Before yield")
|
||||
System.print("Before yield")
|
||||
Fiber.yield()
|
||||
IO.print("After yield")
|
||||
System.print("After yield")
|
||||
}
|
||||
|
||||
fiber.call() // "Before yield"
|
||||
IO.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,
|
||||
|
||||
:::dart
|
||||
var fiber = Fiber.new {
|
||||
IO.print(Fiber.yield()) // "value"
|
||||
System.print(Fiber.yield()) // "value"
|
||||
}
|
||||
|
||||
fiber.call() // Run until the first yield.
|
||||
@@ -65,7 +65,7 @@ later.
|
||||
|
||||
:::dart
|
||||
Fiber.yield()
|
||||
IO.print("this does not get reached")
|
||||
System.print("this does not get reached")
|
||||
|
||||
### Fiber.**yield**(value)
|
||||
|
||||
@@ -77,7 +77,7 @@ Similar to `Fiber.yield` but provides a value to return to the parent fiber's
|
||||
Fiber.yield("value")
|
||||
}
|
||||
|
||||
IO.print(fiber.call()) // "value"
|
||||
System.print(fiber.call()) // "value"
|
||||
|
||||
## Methods
|
||||
|
||||
@@ -87,9 +87,9 @@ Starts or resumes the fiber if it is in a paused state.
|
||||
|
||||
:::dart
|
||||
var fiber = Fiber.new {
|
||||
IO.print("Fiber called")
|
||||
System.print("Fiber called")
|
||||
Fiber.yield()
|
||||
IO.print("Fiber called again")
|
||||
System.print("Fiber called again")
|
||||
}
|
||||
|
||||
fiber.call() // Start it.
|
||||
@@ -103,7 +103,7 @@ If the called fiber is resuming from a yield, the `yield()` method returns
|
||||
|
||||
:::dart
|
||||
var fiber = Fiber.new {
|
||||
IO.print(Fiber.yield())
|
||||
System.print(Fiber.yield())
|
||||
}
|
||||
|
||||
fiber.call()
|
||||
@@ -116,7 +116,7 @@ Invokes the fiber or resumes the fiber if it is in a paused state and sets
|
||||
|
||||
:::dart
|
||||
var fiber = Fiber.new {
|
||||
IO.print(Fiber.yield())
|
||||
System.print(Fiber.yield())
|
||||
}
|
||||
|
||||
fiber.call()
|
||||
|
||||
@@ -13,7 +13,7 @@ argument](../functions.html#block-arguments) to some other method.
|
||||
|
||||
:::dart
|
||||
var fn = Fn.new {
|
||||
IO.print("The body")
|
||||
System.print("The body")
|
||||
}
|
||||
|
||||
It is a runtime error if `function` is not a function.
|
||||
@@ -25,8 +25,8 @@ It is a runtime error if `function` is not a function.
|
||||
The number of arguments the function requires.
|
||||
|
||||
:::dart
|
||||
IO.print(Fn.new {}.arity) // 0.
|
||||
IO.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,7 +34,7 @@ Invokes the function with the given arguments.
|
||||
|
||||
:::dart
|
||||
var fn = Fn.new { |arg|
|
||||
IO.print(arg)
|
||||
System.print(arg)
|
||||
}
|
||||
|
||||
fn.call("Hello world") // Prints "Hello world".
|
||||
|
||||
@@ -20,6 +20,6 @@ All Wren source files automatically have access to the following classes:
|
||||
* [Range](range.html)
|
||||
* [Sequence](sequence.html)
|
||||
* [String](string.html)
|
||||
* [IO](io.html)
|
||||
* [System](system.html)
|
||||
|
||||
[embedding]: ../embedding-api.html
|
||||
|
||||
@@ -1,60 +0,0 @@
|
||||
^title IO Class
|
||||
^category core
|
||||
|
||||
The IO class can be used to read and write to and from the console.
|
||||
|
||||
## Static Methods
|
||||
|
||||
### IO.**print**(objects...)
|
||||
|
||||
Prints a series of objects to the console followed by a newline. Each object is
|
||||
converted to a string by calling `toString` on it. This is overloaded to
|
||||
support up to 16 objects. To pass more, use `printAll()`.
|
||||
|
||||
> IO.print("I like bananas")
|
||||
I like bananas
|
||||
> IO.print("Oranges", 10)
|
||||
Oranges10
|
||||
|
||||
### IO.**printAll**(sequence)
|
||||
|
||||
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.
|
||||
|
||||
> IO.printAll([1, [2, 3], 4])
|
||||
1[2, 3]4
|
||||
|
||||
### IO.**write**(object)
|
||||
|
||||
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.
|
||||
|
||||
> IO.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.
|
||||
|
||||
### IO.**read**()
|
||||
|
||||
Reads in a line of text from stdin. Note that the returned text includes the
|
||||
trailing newline.
|
||||
|
||||
> var name = IO.read()
|
||||
John
|
||||
> IO.print("Hello " + name + "!")
|
||||
Hello John
|
||||
!
|
||||
>
|
||||
|
||||
### IO.**read**(prompt)
|
||||
|
||||
Displays `prompt` then reads in a line of text from stdin. Note that the
|
||||
returned text includes the trailing newline.
|
||||
|
||||
> var name = IO.read("Enter your name: ")
|
||||
Enter your name: John
|
||||
> IO.print("Hello " + name + "!")
|
||||
Hello John
|
||||
!
|
||||
>
|
||||
@@ -26,14 +26,14 @@ Inserts the `item` at `index` in the list.
|
||||
:::dart
|
||||
var list = ["a", "b", "c", "d"]
|
||||
list.insert(1, "e")
|
||||
IO.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.
|
||||
|
||||
:::dart
|
||||
var list = ["a", "b", "c"]
|
||||
list.insert(3, "d")
|
||||
IO.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")
|
||||
IO.print(list) // "[a, b, c, d]"
|
||||
System.print(list) // "[a, b, c, d]".
|
||||
|
||||
Returns the inserted item.
|
||||
|
||||
:::dart
|
||||
IO.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.
|
||||
:::dart
|
||||
var list = ["a", "b", "c", "d"]
|
||||
list.removeAt(1)
|
||||
IO.print(list) // "[a, c, d]".
|
||||
System.print(list) // "[a, c, d]".
|
||||
|
||||
Returns the removed item.
|
||||
|
||||
IO.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.
|
||||
|
||||
:::dart
|
||||
var list = ["a", "b", "c"]
|
||||
IO.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.
|
||||
:::dart
|
||||
var list = ["a", "b", "c"]
|
||||
list[1] = "new"
|
||||
IO.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.
|
||||
|
||||
@@ -50,8 +50,8 @@ map, returns `null`.
|
||||
|
||||
:::dart
|
||||
var map = {"george": "harrison", "ringo": "starr"}
|
||||
IO.print(map["ringo"]) // "starr".
|
||||
IO.print(map["pete"]) // "null".
|
||||
System.print(map["ringo"]) // "starr".
|
||||
System.print(map["pete"]) // "null".
|
||||
|
||||
### **[**key**]=**(value) operator
|
||||
|
||||
|
||||
@@ -7,5 +7,5 @@
|
||||
|
||||
Returns `true`, since `null` is considered [false](../control-flow.html#truth).
|
||||
|
||||
> !null
|
||||
true
|
||||
:::dart
|
||||
System.print(!null) // "true".
|
||||
|
||||
@@ -132,9 +132,9 @@ from the beginning number to the ending number.
|
||||
|
||||
:::dart
|
||||
var range = 1.2..3.4
|
||||
IO.print(range.min) // 1.2
|
||||
IO.print(range.max) // 3.4
|
||||
IO.print(range.isInclusive) // true
|
||||
System.print(range.min) // 1.2
|
||||
System.print(range.max) // 3.4
|
||||
System.print(range.isInclusive) // true
|
||||
|
||||
### **...**(other) operator
|
||||
|
||||
@@ -143,6 +143,6 @@ from the beginning number to the ending number not including the ending number.
|
||||
|
||||
:::dart
|
||||
var range = 1.2...3.4
|
||||
IO.print(range.min) // 1.2
|
||||
IO.print(range.max) // 3.4
|
||||
IO.print(range.isInclusive) // false
|
||||
System.print(range.min) // 1.2
|
||||
System.print(range.max) // 3.4
|
||||
System.print(range.isInclusive) // false
|
||||
|
||||
@@ -59,7 +59,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
|
||||
["one", "two", "three"].each {|word| IO.print(word) }
|
||||
["one", "two", "three"].each {|word| System.print(word) }
|
||||
|
||||
### **isEmpty**
|
||||
|
||||
@@ -88,7 +88,7 @@ original sequence while it is iterated.
|
||||
:::dart
|
||||
var doubles = [1, 2, 3].map {|n| n * 2 }
|
||||
for (n in doubles) {
|
||||
IO.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 +105,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)
|
||||
IO.print(doubles) // [2, 4, 6].
|
||||
System.print(doubles) // [2, 4, 6].
|
||||
|
||||
### **reduce**(function)
|
||||
|
||||
@@ -142,7 +142,7 @@ function `predicate`. If it returns `false`, the element is skipped.
|
||||
:::dart
|
||||
var odds = (1..10).where {|n| n % 2 == 1 }
|
||||
for (n in odds) {
|
||||
IO.print(n) // "1", "3", "5", "7", "9".
|
||||
System.print(n) // "1", "3", "5", "7", "9".
|
||||
}
|
||||
|
||||
The returned sequence is *lazy*. It only applies the filtering when you iterate
|
||||
@@ -160,4 +160,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)
|
||||
IO.print(odds) // [1, 3, 5].
|
||||
System.print(odds) // [1, 3, 5].
|
||||
|
||||
@@ -37,7 +37,7 @@ on strings *return* byte indexes too. So, for example, this does what you want:
|
||||
:::dart
|
||||
var metalBand = "Fäcëhämmër"
|
||||
var hPosition = metalBand.indexOf("h")
|
||||
IO.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
|
||||
@@ -68,7 +68,7 @@ methods, the returned object also has a subscript operator that can be used to
|
||||
directly index bytes.
|
||||
|
||||
:::dart
|
||||
IO.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.
|
||||
|
||||
:::dart
|
||||
var string = "(ᵔᴥᵔ)"
|
||||
IO.print(string.codePoints[0]) // 40, for "(".
|
||||
IO.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`.
|
||||
|
||||
:::dart
|
||||
var string = "(ᵔᴥᵔ)"
|
||||
IO.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)
|
||||
}
|
||||
|
||||
IO.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`.
|
||||
|
||||
:::dart
|
||||
IO.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:
|
||||
|
||||
:::dart
|
||||
IO.print("I ♥ NY"[3]) // One-byte string whose value is 153.
|
||||
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
|
||||
string.
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
^title System Class
|
||||
^category core
|
||||
|
||||
The System class is a grab-bag of functionality exposed by the VM, mostly for
|
||||
use during development or debugging.
|
||||
|
||||
## Static Methods
|
||||
|
||||
### System.**print**()
|
||||
|
||||
Prints a single newline to the console.
|
||||
|
||||
### System.**print**(object)
|
||||
|
||||
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
|
||||
System.print("I like bananas") // Prints "I like bananas".
|
||||
|
||||
### System.**printAll**(sequence)
|
||||
|
||||
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
|
||||
System.printAll([1, [2, 3], 4]) // Prints "1[2, 3]4".
|
||||
|
||||
### System.**write**(object)
|
||||
|
||||
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
|
||||
System.write(4 + 5) // Prints "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.
|
||||
|
||||
### System.**clock**
|
||||
|
||||
Returns the number of seconds (including fractional seconds) since the program
|
||||
was started. This is usually used for benchmarking.
|
||||
Reference in New Issue
Block a user