Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions exercises/concept/backyard-birdwatcher/.docs/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ tail ( seq n -- tailseq ) ! drop first n
{ 1 2 3 4 5 } 3 tail . ! => { 4 5 }
```

Both throw if `n` is larger than the sequence. `index-or-length`
clamps `n` to the sequence's length, so chaining it in turns a
potentially-out-of-range slice into a safe one:
Both throw if `n` is larger than the sequence. If `n` is too big,
`index-or-length` shrinks it down to the sequence's length, so the
slice that follows can't run off the end:

```
index-or-length ( seq n -- seq n' )
Expand Down
25 changes: 20 additions & 5 deletions exercises/concept/cargo-shuffle/.docs/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,10 @@ left to right.
1 2 3 ! stack (bottom → top): 1 2 3
```

There is no other way to pass data around — every word reads its inputs
from the top of the stack and writes its outputs back there. `.` pops
the top value and prints it; `.s` prints the *whole* stack without
consuming anything, which is handy for seeing what a snippet left
behind.
Every word reads its inputs from the top of the stack and writes its
outputs back there. `.` pops the top value and prints it; `.s` prints
the *whole* stack without consuming anything, which is handy for
seeing what a snippet left behind.

## Stack effects

Expand Down Expand Up @@ -65,6 +64,22 @@ crate to the top.
The wider family (`-rot`, `dupd`, `swapd`, `2dup`, …) follows the same
idea; you will meet those words later.

## How words compose

Words written in a row run **left to right**: each word acts on the
stack the word before it left behind. So `dup over` just means "run
`dup`, then run `over` on what `dup` left." Here is what `swap nip`
does to the stack `1 2` (bottom → top), one word at a time:

```factor
1 2 ! 1 2 the starting crates
swap ! 2 1 swap flipped the top two
nip ! 1 nip dropped the 2nd-from-top crate (the 2)
```

Concretely, `dup over` on `1 2` runs `dup` first (leaving `1 2 2`),
then `over` on that (leaving `1 2 2 2`).

## Naming conventions

Words use `lowercase-kebab-case`: lowercase letters joined by hyphens.
Expand Down
4 changes: 2 additions & 2 deletions exercises/concept/currency-conversion/.docs/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ point numbers and pick the right division word for the job.
## Integers and floats

Factor distinguishes integers (`1`, `42`, `1_000_000`) from floating-
point numbers (`1.0`, `3.14`, `6.02e23`). Mixed arithmetic auto-
promotes to a float:
point numbers (`1.0`, `3.14`, `6.02e23`). If you mix an integer and a
float in one calculation, the result comes out as a float:

```factor
2 3 + . ! => 5
Expand Down
10 changes: 6 additions & 4 deletions exercises/concept/high-school-sweetheart/.docs/introduction.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# Introduction

Factor's *function composition* is just the order you write words. A
word's body is itself a sequence of words: each one consumes some
In Factor, you combine words just by writing them one after another —
the order you write them in *is* how they join up. (Programmers call
this *function composition*.) A word's body is itself a sequence of
words: each one consumes some
values from the stack and pushes its result, and the next word picks
up where the previous left off. So defining

Expand All @@ -12,8 +14,8 @@ up where the previous left off. So defining

already *is* the composition of `cleanupname`, `first`, and `1string`.

This exercise also introduces **quotations** — Factor's term for an
anonymous, deferred sequence of words.
This exercise also introduces **quotations** — a piece of code you can
store as a value and run later, instead of running it on the spot.

## Quotations

Expand Down
4 changes: 2 additions & 2 deletions exercises/concept/lasagna/.docs/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ them needs `math` in its `USING:` line.
Every word is documented with a **stack effect** of the form
`( inputs -- outputs )`. It is the word's contract: this word pops the
inputs off the top of the stack and leaves the outputs in their place.
The names inside are documentation for humans — the stack itself is
positional, not named.
The names inside are just there to help you read it. Factor doesn't
use them — it only tracks the *order* values sit in on the stack.

```factor
! + is specified as ( x y -- sum )
Expand Down
Loading