From a2d8557e3e8f58d9adfc028e66caf190d0911aca Mon Sep 17 00:00:00 2001 From: Marshall Lochbaum Date: Tue, 26 Apr 2022 21:25:24 -0400 Subject: Section on composing multiple hook modifiers --- docs/doc/hook.html | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'docs/doc/hook.html') diff --git a/docs/doc/hook.html b/docs/doc/hook.html index 22054800..e300796a 100644 --- a/docs/doc/hook.html +++ b/docs/doc/hook.html @@ -159,3 +159,32 @@ ┘

In the more extreme case of wanting a modifier operand, you might try ({}˙), or (⊣⋈{}˙), or just cheat with .

+

Combinations

+

If you like to go tacit, you'll likely end up stringing together a few s and s at times. Of course the effects are entirely determined by the left-to-right precedence rule for modifiers, but it's interesting to examine what happens in more detail.

+

In the pattern FGH, the ordering doesn't matter at all! That is, it means (FG)H, but this is exactly the same function as F(GH). In both cases, F is applied to 𝕨, H is applied to 𝕩, and G acts on both the results.

+↗️
    4 - 2
+⟨ ¯4 7.38905609893065 ⟩
+
+

I once named this pattern "split compose", but now I think it makes more sense to think of it as two pre-functions added separately to one central function ( above). The whole is exactly the sum of its parts. When applied to just one argument, 𝕩 is reused on both sides, making the composition equivalent to a 3-train.

+↗️
    - 2
+⟨ ¯2 7.38905609893065 ⟩
+
+    (-⋈⋆) 2  # Same thing
+⟨ ¯2 7.38905609893065 ⟩
+
+

More s can be added on the right, making 𝕩 flow through all the added functions. So for example FGH x is x F G H x, and could also be written F(G H) x.

+

A sequence of s is more interesting. It doesn't just compose the functions (for that you need GFH, but note the weird ordering—F applies before G!), but instead passes the current value and the initial function each time. Consider FGHI, or ((FG)H)I: every function but F is on the ring side, meaning it's dyadic!

+

Here's a long example, that might show up if you want to sort an array but have an intolerance for the character . In quicksort, you select a partition element from the array, then divide it into elements less than, and greater than or equal to, the pivot. You'd probably pick a random element for the pivot, but here I'll go with the middle element to avoid having a webpage that generates differently every time!

+↗️
    (⌊≠÷2˙)       "quicksort"  # Index of the pivot
+4
+
+    (⌊≠÷2˙)     "quicksort"  # Select pivot from 𝕩
+'k'
+
+    (⌊≠÷2˙)   "quicksort"  # Compare with 𝕩
+⟨ 1 1 0 0 1 1 1 1 1 ⟩
+
+    (⌊≠÷2˙) "quicksort"  # Use to partition 𝕩
+⟨ "ic" "quksort" ⟩
+
+

Three is rare, but I use two s all the time, as well as followed by , for example the <'a'/ filter on the front page. I think a combination like lotsofstuff/ x reads very nicely when moving from left to right. When I see / I know that I'm filtering x and can read the rest with that context. The reason that has all this power, but not , has nothing to do with the modifiers themselves, as they're completely symmetrical. It's all in the way BQN defines modifier grammar, left to right.

-- cgit v1.2.3