diff options
| author | Marshall Lochbaum <mwlochbaum@gmail.com> | 2021-07-05 22:20:19 -0400 |
|---|---|---|
| committer | Marshall Lochbaum <mwlochbaum@gmail.com> | 2021-07-05 22:20:19 -0400 |
| commit | c96289046dbd42678c10d03ceb5734737392bf4c (patch) | |
| tree | fc897441ab6de8f5453aceb0424ff3969c696d4f /doc/fold.md | |
| parent | 3734638f2f04b5e298dca250f589ae1e4913f88f (diff) | |
Inter-documentation links and minor editing
Diffstat (limited to 'doc/fold.md')
| -rw-r--r-- | doc/fold.md | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/doc/fold.md b/doc/fold.md index 8e8d17a0..e27b7f02 100644 --- a/doc/fold.md +++ b/doc/fold.md @@ -74,7 +74,7 @@ Folding over a list of length 1 never calls the operand function: it returns the !ยด โจโโฉ -Folding over a list of two values applies `๐ฝ` once, since `๐ฝ` is always called on two arguments. But what about zero values? Should `๐ฝ` be applied minus one times? Sort of. BQN checks to see if it knows an *identity value* for the operand function, and returns that, never calling the function. This works for the arithmetic functions we showed above, always returning a single number. +Folding over a list of two values applies `๐ฝ` once, since `๐ฝ` is always called on two arguments. But what about zero values? Should `๐ฝ` be applied minus one times? Sort of. BQN checks to see if it knows an *identity value* for the operand function, and returns that, never calling the function. This works for the [arithmetic functions](arithmetic.md) we showed above, always returning a single number. +ยด โจโฉ # Add nothing up, get zero โยด โจโฉ # The smallest number @@ -94,15 +94,15 @@ The full list of identity values Fold has to use is shown below. ### Right-to-left -The functions we've shown so far are associative (ignoring floating point imprecision), meaning it's equally valid to combine elements of the argument list in any order. But it can be useful to fold using a non-associative function. In this case you must know that Fold performs a *right fold*, starting from the array and working towards the beginning. +The functions we've shown so far are associative (ignoring floating point imprecision), meaning it's equally valid to combine elements of the argument list in any order. But it can be useful to fold using a non-associative function. In this case you must know that Fold performs a *right fold*, starting from the end of the array and working towards the beginning. โโ<ยด "abcd" 'a' โโ< 'b' โโ< 'c' โโ< 'd' # Expanded form -Using the pair function `โโ<` as an operand shows the structure nicely. This fold first pairs the final two characters `'c'` and `'d'`, then pairs `'b'` with that and so on. This matches BQN's right-to-left order of evaluation. More declaratively we might say that each character is paired with the result of folding over everything to its right. +Using the [pair](couple.md#coupling-units) function `โโ<` as an operand shows the structure nicely. This fold first pairs the final two characters `'c'` and `'d'`, then pairs `'b'` with that and so on. This matches BQN's right-to-left order of evaluation. More declaratively we might say that each character is paired with the result of folding over everything to its right. -BQN doesn't provide a left Fold (`` ` `` is Scan). However, you can fold from the left by reversing (`โฝ`) the argument list and also reversing (`ห`) the operand function's argument order. +BQN doesn't provide a left Fold (`` ` `` is [Scan](scan.md)). However, you can fold from the left by [reversing](reverse.md#reverse) (`โฝ`) the argument list and also reversing (`ห`) the operand function's argument order. โโ<หยด โฝ "abcd" |
