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
9 changes: 6 additions & 3 deletions concepts/higher-order-sequences/about.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,11 @@ The full common cast:
| `with` | `( value seq quot -- seq curry )` |
| `without` | `( seq exclude -- newseq )` |
| `sort` | `( seq -- sortedseq )` |
| `infimum` | `( seq -- elt )` |
| `supremum` | `( seq -- elt )` |
| `sum` | `( seq -- n )` |
| `minimum` | `( seq -- elt )` |
| `maximum` | `( seq -- elt )` |
| `minimum-by` | `( seq quot -- elt )` |
| `maximum-by` | `( seq quot -- elt )` |

When *your* word forwards a runtime quotation to one of these
combinators, declare your word with `; inline` so the
Expand All @@ -46,7 +49,7 @@ Beyond the core sequence ops:
| vocab | provides |
|--------------------|-----------------------------------------------|
| `sorting` | `sort`, `sort-by` |
| `math.statistics` | `sum`, `infimum`, `supremum`, `infimum-by`, `supremum-by`, `cum-sum`, `cum-product`, `cum-min`, `cum-max` |
| `math.statistics` | `cum-sum`, `cum-product`, `cum-min`, `cum-max` |
| `grouping` | `group`, `clump`, `monotonic-split` |
| `sets` | `members`, `all-unique?` |

Expand Down
8 changes: 3 additions & 5 deletions concepts/higher-order-sequences/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,8 @@ all? ( seq quot -- ? )
```

`map-sum` (also in `sequences`) maps a quotation across the
sequence and adds the results in one pass. Sorting and aggregation
use the same pattern via [`sorting`][sorting] and
[`math.statistics`][math.statistics]: `sort-by`, `infimum-by`,
`supremum-by`.
sequence and adds the results in one pass. The same pattern
drives `sort-by` (in [`sorting`][sorting]) and `minimum-by` /
`maximum-by` (in `sequences`).

[sorting]: https://docs.factorcode.org/content/vocab-sorting.html
[math.statistics]: https://docs.factorcode.org/content/vocab-math.statistics.html
5 changes: 2 additions & 3 deletions exercises/concept/backyard-birdwatcher/.docs/hints.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

## General

- The [`sequences`][sequences] vocabulary covers nearly everything.
- `sum` lives in [`math.statistics`][math.statistics].
- The [`sequences`][sequences] vocabulary covers nearly everything,
including `sum`.

## 1. Today's count

Expand Down Expand Up @@ -40,4 +40,3 @@
returned unchanged.

[sequences]: https://docs.factorcode.org/content/vocab-sequences.html
[math.statistics]: https://docs.factorcode.org/content/vocab-math.statistics.html
3 changes: 1 addition & 2 deletions exercises/concept/backyard-birdwatcher/.docs/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ strings too — the result is just another string instead of an array:

## Aggregating

`sum` and `product` (in [`math.statistics`][math.statistics])
`sum` and `product` (in [`sequences`][sequences])
add or multiply the elements of a numeric sequence:

```factor
Expand Down Expand Up @@ -188,4 +188,3 @@ back.

[arrays]: https://docs.factorcode.org/content/vocab-arrays.html
[sequences]: https://docs.factorcode.org/content/vocab-sequences.html
[math.statistics]: https://docs.factorcode.org/content/vocab-math.statistics.html
2 changes: 1 addition & 1 deletion exercises/concept/backyard-birdwatcher/.meta/design.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ counts.
- Slice with `head` and `tail`, clamping with `index-or-length`
when the count may exceed the sequence.
- Pad to a target length with `pad-tail` (and `pad-head`).
- Aggregate with `sum` (from `math.statistics`).
- Aggregate with `sum` (from `sequences`).
- Filter-count with `count` and test with `any?`.
- Build a new sequence with `prefix`/`suffix` and
`unclip`/`unclip-last`.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
USING: kernel math math.statistics sequences ;
USING: kernel math sequences ;
IN: backyard-birdwatcher

: today ( days -- count )
Expand Down
3 changes: 1 addition & 2 deletions exercises/concept/boutique-bookkeeping/.docs/hints.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

## 4. Find the cheapest item

- `infimum-by` (in [`math.statistics`][math.statistics]) returns the
- `minimum-by` (in [`sequences`][sequences]) returns the
element whose extracted key is smallest.

## 5. Sum all the prices
Expand All @@ -35,4 +35,3 @@

[sequences]: https://docs.factorcode.org/content/vocab-sequences.html
[sorting]: https://docs.factorcode.org/content/vocab-sorting.html
[math.statistics]: https://docs.factorcode.org/content/vocab-math.statistics.html
25 changes: 12 additions & 13 deletions exercises/concept/boutique-bookkeeping/.docs/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,23 +128,23 @@ map-sum ( seq quot -- n )

## Min and max

`infimum` and `supremum` return the smallest or largest element
of a sequence outright. `infimum-by` and `supremum-by` (all in
[`math.statistics`][math.statistics]) return the element whose
extracted key is smallest or largest:
`minimum` and `maximum` return the smallest or largest element
of a sequence outright. `minimum-by` and `maximum-by` (all in
[`sequences`][sequences]) return the element whose extracted
key is smallest or largest:

```
infimum ( seq -- elt )
supremum ( seq -- elt )
infimum-by ( seq quot -- elt )
supremum-by ( seq quot -- elt )
minimum ( seq -- elt )
maximum ( seq -- elt )
minimum-by ( seq quot -- elt )
maximum-by ( seq quot -- elt )
```

```factor
{ 3 1 4 1 5 9 2 6 } infimum . ! => 1
{ 3 1 4 1 5 9 2 6 } supremum . ! => 9
{ 3 1 4 1 5 9 2 6 } minimum . ! => 1
{ 3 1 4 1 5 9 2 6 } maximum . ! => 9

{ -3 5 -1 4 } [ abs ] infimum-by .
{ -3 5 -1 4 } [ abs ] minimum-by .
! => -1
```

Expand All @@ -157,7 +157,7 @@ each call site, where the quotation is a known literal — without
it, the compiler has no way to know the quotation's stack effect.

```factor
USING: math.statistics sequences ;
USING: math sequences ;

: tax-on ( inventory quot -- total )
map-sum ; inline
Expand Down Expand Up @@ -188,5 +188,4 @@ turns a number into its decimal-string form:
[kernel]: https://docs.factorcode.org/content/vocab-kernel.html
[sequences]: https://docs.factorcode.org/content/vocab-sequences.html
[sorting]: https://docs.factorcode.org/content/vocab-sorting.html
[math.statistics]: https://docs.factorcode.org/content/vocab-math.statistics.html
[math.parser]: https://docs.factorcode.org/content/vocab-math.parser.html
4 changes: 2 additions & 2 deletions exercises/concept/boutique-bookkeeping/.meta/design.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ items.

- Pass quotations to `filter`, `reject`, `count`, `map`, and `map-sum`.
- Sort with `sort-by` from `sorting`.
- Pick extreme elements with `infimum-by` and `supremum-by` from
`math.statistics`.
- Pick extreme elements with `minimum-by` and `maximum-by` from
`sequences`.

## Out of scope

Expand Down
4 changes: 2 additions & 2 deletions exercises/concept/boutique-bookkeeping/.meta/exemplar.factor
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
USING: kernel math math.parser math.statistics sequences sorting ;
USING: kernel math math.parser sequences sorting ;
IN: boutique-bookkeeping

: sort-by-price ( inventory -- sorted )
Expand All @@ -11,7 +11,7 @@ IN: boutique-bookkeeping
swap [ second < ] with count ;

: cheapest-item ( inventory -- item )
[ second ] infimum-by ;
[ second ] minimum-by ;

: total-price ( inventory -- sum )
[ second ] map-sum ;
Expand Down
2 changes: 1 addition & 1 deletion exercises/concept/quayside-crew/.docs/hints.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## 1. `weigh-crate`

- One word from `math.statistics` does it.
- One word from `sequences` does it.

## 2. `weigh-all`

Expand Down
3 changes: 1 addition & 2 deletions exercises/concept/quayside-crew/.meta/exemplar.factor
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
USING: accessors concurrency.combinators concurrency.locks
concurrency.promises kernel locals math math.statistics sequences
threads ;
concurrency.promises kernel locals math sequences threads ;
IN: quayside-crew

: weigh-crate ( crate -- weight )
Expand Down
4 changes: 2 additions & 2 deletions exercises/practice/high-scores/.meta/example.factor
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
USING: accessors kernel math math.order math.statistics sequences sorting ;
USING: accessors kernel math math.order sequences sorting ;
IN: high-scores

TUPLE: high-scores scores ;
Expand All @@ -13,7 +13,7 @@ TUPLE: high-scores scores ;
scores>> last ;

: personal-best ( hs -- score )
scores>> supremum ;
scores>> maximum ;

: personal-top-three ( hs -- top-three )
scores>> sort reverse 3 over length min head ;
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
USING: combinators grouping kernel math math.parser math.statistics sequences strings unicode ;
USING: combinators grouping kernel math math.parser sequences strings unicode ;
IN: largest-series-product

ERROR: invalid-input ;
Expand All @@ -9,5 +9,5 @@ ERROR: invalid-input ;
{ [ 2dup [ length ] dip < ] [ 2drop invalid-input ] }
{ [ over [ digit? ] all? not ] [ 2drop invalid-input ] }
{ [ dup 0 = ] [ 2drop 1 ] }
[ clump [ [ digit> ] map product ] map supremum ]
[ clump [ [ digit> ] map product ] map maximum ]
} cond ;
2 changes: 1 addition & 1 deletion exercises/practice/scrabble-score/.meta/example.factor
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
USING: assocs kernel math.statistics sequences unicode ;
USING: assocs kernel sequences unicode ;
IN: scrabble-score

CONSTANT: letter-scores H{
Expand Down