From c96289046dbd42678c10d03ceb5734737392bf4c Mon Sep 17 00:00:00 2001 From: Marshall Lochbaum Date: Mon, 5 Jul 2021 22:20:19 -0400 Subject: Inter-documentation links and minor editing --- docs/doc/fold.html | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'docs/doc/fold.html') diff --git a/docs/doc/fold.html b/docs/doc/fold.html index 7c03d174..7c2703c8 100644 --- a/docs/doc/fold.html +++ b/docs/doc/fold.html @@ -69,7 +69,7 @@ ↗️
    !´ 
-

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 we showed above, always returning a single number.

↗️
    +´ ⟨⟩  # Add nothing up, get zero
 0
     ´ ⟨⟩  # The smallest number
@@ -133,15 +133,15 @@
 
 
 

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' "cd" ⟩ ⟩
 
     'a' < 'b' < 'c' < 'd'  # Expanded form
 ⟨ 'a' ⟨ 'b' "cd" ⟩ ⟩
 
-

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.

-

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.

+

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.

+

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.

↗️
    <˜´  "abcd"
 ⟨ ⟨ "ab" 'c' ⟩ 'd' ⟩
 
-- cgit v1.2.3