aboutsummaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
Diffstat (limited to 'docs')
-rw-r--r--docs/optionals.md44
1 files changed, 22 insertions, 22 deletions
diff --git a/docs/optionals.md b/docs/optionals.md
index 584625fe..a0f54626 100644
--- a/docs/optionals.md
+++ b/docs/optionals.md
@@ -35,36 +35,36 @@ Optional types are written using a `?` after the type name. So, an optional
integer would be written as `Int?` and an optional array of texts would be
written as `[Text]?`.
-Null values can be written explicitly using the `!` prefix operator and the
-type of null value. For example, if you wanted to declare a variable that could
-be either an integer value or a null value and initialize it as a null value,
-you would write it as:
+None can be written explicitly using `NONE` with a type annotation. For
+example, if you wanted to declare a variable that could be either an integer
+value or `NONE` and initialize it as none, you would write it as:
```tomo
-x := !Int
+x := NONE:Int
```
Similarly, if you wanted to declare a variable that could be an array of texts
-or null and initialize it as null, you would write:
+or none and initialize it as none, you would write:
```tomo
x := ![Text]
```
-If you want to declare a variable and initialize it with a non-null value, but
-keep open the possibility of assigning a null value later, you can use the
-postfix `?` operator to indicate that a value is optional:
+If you want to declare a variable and initialize it with a non-none value, but
+keep open the possibility of assigning `NONE` later, you can use the postfix
+`?` operator to indicate that a value is optional:
```tomo
x := 5?
-# Later on, assign null:
+# Later on, assign none:
x = !Int
```
## Type Inference
-For convenience, null values can also be written as `NONE` for any type in
-situations where the compiler knows what type of optional value is expected:
+For convenience, `NONE` can also be written without the explicit type
+annotation for any type in situations where the compiler knows what type of
+optional value is expected:
- When assigning to a variable that has already been declared as optional.
- When returning from a function with an explicit optional return type.
@@ -82,7 +82,7 @@ func doop(arg:Int?)->Text?:
doop(NONE)
```
-Non-null values can also be automatically promoted to optional values without
+Non-none values can also be automatically promoted to optional values without
the need for an explicit `?` operator in the cases listed above:
```tomo
@@ -95,12 +95,12 @@ func doop(arg:Int?)->Text?:
doop(123)
```
-## Null Checking
+## None Checking
-In addition to using conditionals to check for null values, you can also use
-`or` to get a non-null value by either providing an alternative non-null value
-or by providing an early out statement like `return`/`skip`/`stop` or a function
-with an `Abort` type like `fail()` or `exit()`:
+In addition to using conditionals to check for `NONE`, you can also use `or` to
+get a non-none value by either providing an alternative non-none value or by
+providing an early out statement like `return`/`skip`/`stop` or a function with
+an `Abort` type like `fail()` or `exit()`:
```tomo
maybe_x := 5?
@@ -120,7 +120,7 @@ func do_stuff(matches:[Text]):
for line in lines:
matches := line:matches($/{..},{..}/) or skip
- # The `or skip` above means that if we're here, `matches` is non-null:
+ # The `or skip` above means that if we're here, `matches` is non-none:
do_stuff(matches)
```
@@ -132,9 +132,9 @@ booleans, texts, enums, nums, or integers (`Int` type only). This is done by
using carefully chosen values, such as `0` for pointers, `2` for booleans, or a
negative length for arrays. However, for fixed-size integers (`Int64`, `Int32`,
`Int16`, and `Int8`), bytes, and structs, an additional byte is required for
-out-of-band information about whether the value is null or not.
+out-of-band information about whether the value is none or not.
-Floating point numbers (`Num` and `Num32`) use `NaN` to represent null, so
-optional nums should be careful to avoid using `NaN` as a non-null value. This
+Floating point numbers (`Num` and `Num32`) use `NaN` to represent none, so
+optional nums should be careful to avoid using `NaN` as a non-none value. This
option was chosen to minimize the memory overhead of optional nums and because
`NaN` literally means "not a number".