mirror of
https://github.com/wren-lang/wren.git
synced 2026-01-09 21:28:39 +01:00
Update a bunch of io to IO in docs.
This commit is contained in:
@ -15,7 +15,7 @@ consider a module effectively a class. Consider:
|
||||
}
|
||||
|
||||
class Inner {
|
||||
io.write(_blah) // Does this declare field in Inner, or access Outer?
|
||||
IO.write(_blah) // Does this declare field in Inner, or access Outer?
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -30,7 +30,7 @@ getters for them that return fields.
|
||||
That's weird if you take into account setters, though. Consider:
|
||||
|
||||
class Foo {
|
||||
a { io.write(_prop) }
|
||||
a { IO.write(_prop) }
|
||||
_prop = value { ... }
|
||||
}
|
||||
|
||||
|
||||
@ -26,7 +26,7 @@ a top-level function in another module would be something like:
|
||||
This leaves the question of how *do* you call top level functions in your own
|
||||
module? I.e., how do we call foo here:
|
||||
|
||||
def foo(arg) { io.write("called foo!") }
|
||||
def foo(arg) { IO.write("called foo!") }
|
||||
|
||||
class SomeClass {
|
||||
bar {
|
||||
@ -37,7 +37,7 @@ module? I.e., how do we call foo here:
|
||||
This is analogous to:
|
||||
|
||||
class SomeModule {
|
||||
static foo(arg) { io.write("called foo!") }
|
||||
static foo(arg) { IO.write("called foo!") }
|
||||
|
||||
class SomeClass {
|
||||
bar {
|
||||
|
||||
@ -19,27 +19,27 @@ This means `0`, empty strings, and empty collections are all considered "true" v
|
||||
The simplest branching statement, `if` lets you conditionally skip a chunk of code. It looks like this:
|
||||
|
||||
:::wren
|
||||
if (ready) io.write("go!")
|
||||
if (ready) IO.write("go!")
|
||||
|
||||
That evaluates the parenthesized expression after `if`. If it's true, then the statement after the condition is evaluated. Otherwise it is skipped. Instead of a statement, you can have a block:
|
||||
|
||||
:::wren
|
||||
if (ready) {
|
||||
io.write("getSet")
|
||||
io.write("go!")
|
||||
IO.write("getSet")
|
||||
IO.write("go!")
|
||||
}
|
||||
|
||||
You may also provide an `else` branch. It will be executed if the condition is false:
|
||||
|
||||
:::wren
|
||||
if (ready) io.write("go!") else io.write("not ready!")
|
||||
if (ready) IO.write("go!") else IO.write("not ready!")
|
||||
|
||||
And, of course, it can take a block too:
|
||||
|
||||
if (ready) {
|
||||
io.write("go!")
|
||||
IO.write("go!")
|
||||
} else {
|
||||
io.write("not ready!")
|
||||
IO.write("not ready!")
|
||||
}
|
||||
|
||||
## The logical operators `&&` and `||`
|
||||
@ -49,13 +49,13 @@ The `&&` and `||` operators are lumped here under branching because they conditi
|
||||
An `&&` ("logical and") expression evaluates the left-hand argument. If it's falsey, it returns that value. Otherwise it evaluates and returns the right-hand argument.
|
||||
|
||||
:::wren
|
||||
io.write(false && 1) // false
|
||||
io.write(1 && 2) // 2
|
||||
IO.write(false && 1) // false
|
||||
IO.write(1 && 2) // 2
|
||||
|
||||
An `||` ("logical or") expression is reversed. If the left-hand argument is truthy, it's returned, otherwise the right-hand argument is evaluated and returned:
|
||||
|
||||
:::wren
|
||||
io.write(false || 1) // 1
|
||||
io.write(1 || 2) // 1
|
||||
IO.write(false || 1) // 1
|
||||
IO.write(1 || 2) // 1
|
||||
|
||||
**TODO: Conditional operator.**
|
||||
|
||||
@ -4,7 +4,7 @@ Wren is object-oriented, so most code consists of method calls. Most of them
|
||||
look like so:
|
||||
|
||||
:::wren
|
||||
io.write("hello")
|
||||
IO.write("hello")
|
||||
items.add("another")
|
||||
items.insert(1, "value")
|
||||
|
||||
|
||||
@ -38,8 +38,8 @@ never write `;` unless you want to cram a bunch of statements on one line.
|
||||
|
||||
:::dart
|
||||
// Two statements:
|
||||
io.write("hi")
|
||||
io.write("bye")
|
||||
IO.write("hi")
|
||||
IO.write("bye")
|
||||
|
||||
Sometimes, though, a statement doesn't fit on a single line and treating the
|
||||
newline as a semicolon would trip things up. To handle that, Wren has a very
|
||||
|
||||
@ -12,7 +12,7 @@ defined, it can be accessed by name as you would expect.
|
||||
|
||||
:::dart
|
||||
var animal = "Slow Loris"
|
||||
io.write(animal) // Prints "Slow Loris".
|
||||
IO.write(animal) // Prints "Slow Loris".
|
||||
|
||||
## Scope
|
||||
|
||||
@ -21,11 +21,11 @@ defined until the end of the block where that definition appears.
|
||||
|
||||
:::dart
|
||||
{
|
||||
io.write(a) // ERROR! a doesn't exist yet.
|
||||
IO.write(a) // ERROR! a doesn't exist yet.
|
||||
var a = 123
|
||||
io.write(a) // "123"
|
||||
IO.write(a) // "123"
|
||||
}
|
||||
io.write(a) // ERROR! a doesn't exist anymore.
|
||||
IO.write(a) // ERROR! a doesn't exist anymore.
|
||||
|
||||
Variables defined at the top level of a script are *global*. All other variables
|
||||
are *local*. Declaring a variable in an inner scope with the same name as an
|
||||
@ -36,9 +36,9 @@ something you likely intend to do much).
|
||||
var a = "outer"
|
||||
{
|
||||
var a = "inner"
|
||||
io.write(a) // Prints "inner".
|
||||
IO.write(a) // Prints "inner".
|
||||
}
|
||||
io.write(a) // Prints "outer".
|
||||
IO.write(a) // Prints "outer".
|
||||
|
||||
Declaring a variable with the same name in the *same* scope *is* an error.
|
||||
|
||||
@ -63,6 +63,6 @@ assigned value.
|
||||
|
||||
:::dart
|
||||
var a = "before"
|
||||
io.write(a = "after") // Prints "after".
|
||||
IO.write(a = "after") // Prints "after".
|
||||
|
||||
**TODO: Forward references for globals, closures.**
|
||||
|
||||
Reference in New Issue
Block a user