File tree Expand file tree Collapse file tree
backyard-birdwatcher/.docs Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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
58The basic three are in ` kernel ` :
69
Original file line number Diff line number Diff line change 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
410takes a boolean and two quotations, running the first if the
511boolean is truthy and the second otherwise.
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change @@ -50,6 +50,22 @@ between? ( x lo hi -- ? ) ! lo <= x <= hi (inclusive)
5050You'll often see it as a ` cond ` predicate — ` dup 1 4 between? ` —
5151to 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
You can’t perform that action at this time.
0 commit comments