2015-06-28 18:45:08 +00:00
|
|
|
^title IO Class
|
2015-05-30 15:10:14 +00:00
|
|
|
^category core
|
|
|
|
|
|
|
|
|
|
The IO class can be used to read and write to and from the console.
|
|
|
|
|
|
|
|
|
|
## Static Methods
|
|
|
|
|
|
2015-07-01 15:11:10 +00:00
|
|
|
### IO.**print**(objects...)
|
2015-06-27 11:50:29 +00:00
|
|
|
|
2015-07-18 21:09:00 +00:00
|
|
|
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()`.
|
2015-05-30 15:10:14 +00:00
|
|
|
|
2015-07-18 21:09:00 +00:00
|
|
|
> IO.print("I like bananas")
|
|
|
|
|
I like bananas
|
|
|
|
|
> IO.print("Oranges", 10)
|
|
|
|
|
Oranges10
|
2015-05-30 15:10:14 +00:00
|
|
|
|
2015-07-18 21:09:00 +00:00
|
|
|
### 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
|
2015-05-30 15:10:14 +00:00
|
|
|
|
2015-07-01 15:11:10 +00:00
|
|
|
### IO.**write**(object)
|
2015-06-27 11:50:29 +00:00
|
|
|
|
2015-07-18 21:09:00 +00:00
|
|
|
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.
|
2015-05-30 15:10:14 +00:00
|
|
|
|
2015-07-18 21:09:00 +00:00
|
|
|
> IO.write(4 + 5)
|
|
|
|
|
9>
|
2015-05-30 15:10:14 +00:00
|
|
|
|
2015-07-01 15:11:10 +00:00
|
|
|
In the above example, the result of `4 + 5` is printed, and then the prompt is
|
2015-06-27 11:50:29 +00:00
|
|
|
printed on the same line because no newline character was printed afterwards.
|
2015-05-30 15:10:14 +00:00
|
|
|
|
2015-07-18 21:09:00 +00:00
|
|
|
### 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
|
|
|
|
|
!
|
|
|
|
|
>
|
|
|
|
|
|
2015-07-01 15:11:10 +00:00
|
|
|
### IO.**read**(prompt)
|
2015-06-27 11:50:29 +00:00
|
|
|
|
2015-07-18 21:09:00 +00:00
|
|
|
Displays `prompt` then reads in a line of text from stdin. Note that the
|
|
|
|
|
returned text includes the trailing newline.
|
2015-05-30 15:10:14 +00:00
|
|
|
|
2015-07-18 21:09:00 +00:00
|
|
|
> var name = IO.read("Enter your name: ")
|
|
|
|
|
Enter your name: John
|
|
|
|
|
> IO.print("Hello " + name + "!")
|
|
|
|
|
Hello John
|
|
|
|
|
!
|
|
|
|
|
>
|