SO MUCH NEW DOCS OH WOW.

This commit is contained in:
Bob Nystrom
2015-01-03 23:27:02 -08:00
parent c25cfca18b
commit a8726e6c00
22 changed files with 1204 additions and 531 deletions
+31 -11
View File
@@ -3,15 +3,20 @@
Values are the built-in object types that all other objects are composed of.
They can be created through *literals*, expressions that evaluate to a value.
All values are *immutable*—once created, they do not change. The number
`3` is always the number `3`. The string `"frozen"` can never have its
character array modified in place.
## Booleans
A boolean value represents truth or falsehood. There are two boolean literals,
`true` and `false`. Its class is `Bool`.
`true` and `false`. Their class is `Bool`.
## Numbers
Like other scripting languages, Wren has a single numeric type: double-precision floating point. Number literals look like you expect coming from other languages:
Like other scripting languages, Wren has a single numeric type:
double-precision floating point. Number literals look like you expect coming
from other languages:
:::dart
0
@@ -25,33 +30,48 @@ Numbers are instances of the `Num` class.
## Strings
Strings are chunks of text. String literals are surrounded in double quotes:
Strings are chunks of text stored as UTF-8. Their class is `String`. String
literals are surrounded in double quotes:
:::dart
"hi there"
A couple of escape characters are supported:
A handful of escape characters are supported:
:::dart
"\n" // Newline.
"\"" // A double quote character.
"\\" // A backslash.
"\a" // Alarm beep. (Who uses this?)
"\b" // Backspace.
"\f" // Formfeed.
"\n" // Newline.
"\r" // Carriage return.
"\t" // Tab.
"\v" // Vertical tab.
Their class is `String`.
A `\u` followed by four hex digits can be used to specify a Unicode code point.
## Ranges
A range is a little object that represents a consecutive range of numbers. They don't have their own dedicated literal syntax. Instead, the number class implements `..` and `...` operators to create them:
A range is a little object that represents a consecutive range of integers.
They don't have their own dedicated literal syntax. Instead, the number class
implements the `..` and `...` [operators](expressions.html#operators) to create
them:
:::dart
3..8
This creates a range from three two eight, including eight itself. If you want a half-inclusive range, use `...`:
This creates a range from three to eight, including eight itself. If you want a
half-inclusive range, use `...`:
:::dart
4...6
This creates a range from four to six *not* including six itself. Ranges are commonly used for [looping](looping.html) over a sequences of numbers, but are useful in other places too. You can pass them to a [list](lists.html)'s subscript operator to return a subset of the list, for example:
This creates a range from four to six *not* including six itself. Ranges are
commonly used for [iterating](control-flow.html#for-statements) over a
sequences of numbers, but are useful in other places too. You can pass them to
a [list](lists.html)'s subscript operator to return a subset of the list, for
example:
:::dart
var list = ["a", "b", "c", "d", "e"]
@@ -60,7 +80,7 @@ This creates a range from four to six *not* including six itself. Ranges are com
## Null
Wren has a special value `null`, which is the only instance of the class `Null`.
(Note the difference in case.) It functions a bit like `void` in some
Wren has a special value `null`, which is the only instance of the class
`Null`. (Note the difference in case.) It functions a bit like `void` in some
languages: it indicates the absence of a value. If you call a method that
doesn't return anything and get its returned value, you get `null` back.