Edit docs. Docs docs docs.

This commit is contained in:
Bob Nystrom
2017-10-19 19:52:05 -07:00
parent f8076c2c1c
commit e043a95e4e
4 changed files with 82 additions and 66 deletions
+13 -5
View File
@@ -107,17 +107,17 @@ Blocks of this form when used for method and function bodies automatically
return `null` after the block has completed. If you want to return a different
value, you need an explicit `return` statement.
However, it's pretty common to have a method or function that just evaluates
and returns the result of a single expression. For that, Wren has a more
compact notation:
However, it's pretty common to have a method or function that just evaluates and
returns the result of a single expression. Some other languages use `=>` to
define these. Wren uses:
:::wren
{ "single expression" }
If there is no newline after the `{` (or after the parameter list in a
[function](functions.html)), then the block may only contain a single
expression, and it automatically returns the result of it. It's exactly the
same as doing:
expression, and it automatically returns the result of it. It's exactly the same
as doing:
:::wren
{
@@ -136,6 +136,14 @@ put a newline in there:
}
}
Using an initial newline after the `{` does feel a little weird or magical, but
newlines are already significant in Wren, so it's not totally crazy. The nice
thing about this syntax as opposed to something like `=>` is that the *end* of
the block has an explicit delimiter. That helps when chaining:
:::wren
numbers.map {|n| n * 2 }.where {|n| n < 100 }
## Precedence and Associativity
We'll talk about Wren's different expression forms and what they mean in the