docs: revise branching, classes, index, looping, qa, syntax docs and add concurrency/error-handling nav entries
This commit is contained in:
+10
-10
@@ -9,7 +9,7 @@ Classes contain both *behavior* and *state*. Behavior is defined in *methods* wh
|
||||
|
||||
Classes are created using the `class` keyword, unsurprisingly:
|
||||
|
||||
:::wren
|
||||
:::dart
|
||||
class Unicorn {}
|
||||
|
||||
This creates a class named `Unicorn` with no methods or fields.
|
||||
@@ -18,35 +18,35 @@ This creates a class named `Unicorn` with no methods or fields.
|
||||
|
||||
To make our unicorn do stuff, we need to give it methods.
|
||||
|
||||
:::wren
|
||||
:::dart
|
||||
class Unicorn {
|
||||
prance {
|
||||
IO.write("The unicorn prances in a fancy manner!")
|
||||
IO.print("The unicorn prances in a fancy manner!")
|
||||
}
|
||||
}
|
||||
|
||||
This defines a `prance` method that takes no arguments. To support parameters, add a parenthesized parameter list after the method's name:
|
||||
|
||||
:::wren
|
||||
:::dart
|
||||
// Inside class...
|
||||
prance(where, when) {
|
||||
IO.write("The unicorn prances in " + where + " at " + when)
|
||||
IO.print("The unicorn prances in " + where + " at " + when)
|
||||
}
|
||||
|
||||
Unlike most other dynamically-typed languages, in Wren you can have multiple methods in a class with the same name, as long as they take a different number of parameters. In other words, you can overload by arity. So this class is fine:
|
||||
|
||||
:::wren
|
||||
:::dart
|
||||
class Unicorn {
|
||||
prance {
|
||||
IO.write("The unicorn prances in a fancy manner!")
|
||||
IO.print("The unicorn prances in a fancy manner!")
|
||||
}
|
||||
|
||||
prance(where) {
|
||||
IO.write("The unicorn prances in " + where)
|
||||
IO.print("The unicorn prances in " + where)
|
||||
}
|
||||
|
||||
prance(where, when) {
|
||||
IO.write("The unicorn prances in " + where + " at " + when)
|
||||
IO.print("The unicorn prances in " + where + " at " + when)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,7 +72,7 @@ A class can inherit from a "parent" or *superclass*. When you invoke a method on
|
||||
|
||||
By default, any new class inherits from `Object`, which is the superclass from which all other classes ultimately descend. You can specify a different parent class using `is` when you declare the class:
|
||||
|
||||
:::class
|
||||
:::dart
|
||||
class Pegasus is Unicorn {}
|
||||
|
||||
This declares a new class `Pegasus` that inherits from `Unicorn`.
|
||||
|
||||
Reference in New Issue
Block a user