Skip to content

Commit a785bb7

Browse files
address lesson feedback (#280)
1 parent e3602a2 commit a785bb7

4 files changed

Lines changed: 29 additions & 3 deletions

File tree

concepts/conditionals/about.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# About
22

3-
Factor's conditionals all take quotations as their branches.
3+
Factor's conditionals all take **quotations** as their branches — code
4+
written in square brackets, `[ ... ]`, that is pushed as a value rather
5+
than run until the conditional selects it. (Quotations themselves are
6+
covered fully in a later exercise.)
47

58
The basic three are in `kernel`:
69

concepts/conditionals/introduction.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Introduction
22

3+
Factor's conditionals choose between **quotations** — snippets of code
4+
written in square brackets, `[ ... ]`. Writing `[ ... ]` pushes the
5+
code onto the stack as a value rather than running it; the conditional
6+
then decides which quotation to run. (Quotations are covered fully in a
7+
later exercise.)
8+
39
`if` (in [`kernel`][kernel]) is Factor's basic conditional. It
410
takes a boolean and two quotations, running the first if the
511
boolean is truthy and the second otherwise.

exercises/concept/backyard-birdwatcher/.docs/introduction.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ A literal array uses `{ }` with whitespace between elements:
1313
{ "a" "b" "c" } . ! => { "a" "b" "c" }
1414
```
1515

16-
Arrays are read-only — words like `suffix` and `remove-nth` return
17-
a *new* sequence rather than mutating the original.
16+
Arrays are fixed-length, so words like `suffix` and `remove-nth`
17+
which change how many elements there are — return a *new* sequence
18+
rather than growing the original.
1819

1920
## Length and indexing
2021

exercises/concept/cars-assemble/.docs/introduction.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,22 @@ between? ( x lo hi -- ? ) ! lo <= x <= hi (inclusive)
5050
You'll often see it as a `cond` predicate — `dup 1 4 between?`
5151
to pick a branch by range rather than by a single value.
5252

53+
## Quotations
54+
55+
The comparison words above produce booleans; to *act* on a boolean you
56+
hand the conditional one or more **quotations**. A quotation is a
57+
snippet of code wrapped in square brackets, `[ ... ]`. Writing it
58+
pushes the code onto the stack as a value instead of running it — a
59+
word like `if` then decides which quotation to run.
60+
61+
```factor
62+
[ neg ] ! a quotation that negates the top of the stack
63+
[ ] ! the empty quotation — does nothing
64+
```
65+
66+
A later exercise covers quotations in full; for now, read
67+
`[ ... ]` as "the code to run for this branch."
68+
5369
## `if`, `when`, `unless`
5470

5571
`if` (in [`kernel`][kernel]) takes a boolean and two quotations. It

0 commit comments

Comments
 (0)