diff --git a/concepts/conditionals/about.md b/concepts/conditionals/about.md index 5f8c3509..8a75e4e0 100644 --- a/concepts/conditionals/about.md +++ b/concepts/conditionals/about.md @@ -1,6 +1,9 @@ # About -Factor's conditionals all take quotations as their branches. +Factor's conditionals all take **quotations** as their branches — code +written in square brackets, `[ ... ]`, that is pushed as a value rather +than run until the conditional selects it. (Quotations themselves are +covered fully in a later exercise.) The basic three are in `kernel`: diff --git a/concepts/conditionals/introduction.md b/concepts/conditionals/introduction.md index facbda93..e8ed2898 100644 --- a/concepts/conditionals/introduction.md +++ b/concepts/conditionals/introduction.md @@ -1,5 +1,11 @@ # Introduction +Factor's conditionals choose between **quotations** — snippets of code +written in square brackets, `[ ... ]`. Writing `[ ... ]` pushes the +code onto the stack as a value rather than running it; the conditional +then decides which quotation to run. (Quotations are covered fully in a +later exercise.) + `if` (in [`kernel`][kernel]) is Factor's basic conditional. It takes a boolean and two quotations, running the first if the boolean is truthy and the second otherwise. diff --git a/exercises/concept/backyard-birdwatcher/.docs/introduction.md b/exercises/concept/backyard-birdwatcher/.docs/introduction.md index 43cdd399..df3ca544 100644 --- a/exercises/concept/backyard-birdwatcher/.docs/introduction.md +++ b/exercises/concept/backyard-birdwatcher/.docs/introduction.md @@ -13,8 +13,9 @@ A literal array uses `{ }` with whitespace between elements: { "a" "b" "c" } . ! => { "a" "b" "c" } ``` -Arrays are read-only — words like `suffix` and `remove-nth` return -a *new* sequence rather than mutating the original. +Arrays are fixed-length, so words like `suffix` and `remove-nth` — +which change how many elements there are — return a *new* sequence +rather than growing the original. ## Length and indexing diff --git a/exercises/concept/cars-assemble/.docs/introduction.md b/exercises/concept/cars-assemble/.docs/introduction.md index 9e263f94..a7c5060e 100644 --- a/exercises/concept/cars-assemble/.docs/introduction.md +++ b/exercises/concept/cars-assemble/.docs/introduction.md @@ -50,6 +50,22 @@ between? ( x lo hi -- ? ) ! lo <= x <= hi (inclusive) You'll often see it as a `cond` predicate — `dup 1 4 between?` — to pick a branch by range rather than by a single value. +## Quotations + +The comparison words above produce booleans; to *act* on a boolean you +hand the conditional one or more **quotations**. A quotation is a +snippet of code wrapped in square brackets, `[ ... ]`. Writing it +pushes the code onto the stack as a value instead of running it — a +word like `if` then decides which quotation to run. + +```factor +[ neg ] ! a quotation that negates the top of the stack +[ ] ! the empty quotation — does nothing +``` + +A later exercise covers quotations in full; for now, read +`[ ... ]` as "the code to run for this branch." + ## `if`, `when`, `unless` `if` (in [`kernel`][kernel]) takes a boolean and two quotations. It