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
12 changes: 8 additions & 4 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -1306,7 +1306,8 @@
"unicode",
"arrays",
"windows",
"locals"
"locals",
"while"
],
"difficulty": 5
},
Expand Down Expand Up @@ -1469,7 +1470,8 @@
"sequences",
"dynamic-variables",
"mutation",
"bitwise-operations"
"bitwise-operations",
"while"
],
"difficulty": 7
},
Expand Down Expand Up @@ -1501,7 +1503,8 @@
"higher-order-sequences",
"sequences",
"strings",
"locals"
"locals",
"while"
],
"difficulty": 7
},
Expand Down Expand Up @@ -1556,7 +1559,8 @@
"combinators",
"errors",
"mutation",
"locals"
"locals",
"while"
],
"difficulty": 8
},
Expand Down
13 changes: 13 additions & 0 deletions exercises/concept/backyard-birdwatcher/.docs/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,19 @@ index-or-length ( seq n -- seq n' )
{ 10 20 } 3 index-or-length head . ! => { 10 20 }
```

The starred variants `head*` and `tail*` count from the end —
`head*` drops the last `n`, `tail*` keeps the last `n`:

```
head* ( seq n -- headseq ) ! everything except the last n
tail* ( seq n -- tailseq ) ! the last n elements
```

```factor
{ 1 2 3 4 5 } 2 head* . ! => { 1 2 3 }
{ 1 2 3 4 5 } 2 tail* . ! => { 4 5 }
```

For an arbitrary slice between two indices, `subseq` takes the
*start* (inclusive) and *end* (exclusive):

Expand Down
12 changes: 12 additions & 0 deletions exercises/concept/lasagna-luminary/.docs/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,18 @@ H{ { "a" 1 } { "b" 2 } }
! => H{ { "a" -1 } { "b" -2 } }
```

The same shape works for `map-index` (in [`sequences`][sequences]),
whose quotation receives the element *and* its index. The names
make clear which operand plays which role:

```factor
USING: locals sequences ;

! Divide each element by its 1-based position:
{ 10 80 270 } [| elt i | elt i 1 + / ] map-index .
! => { 10 40 90 }
```

The lambda's stack effect is determined by the input list and what
its body produces.

Expand Down