diff options
| author | Marshall Lochbaum <mwlochbaum@gmail.com> | 2022-05-28 21:55:15 -0400 |
|---|---|---|
| committer | Marshall Lochbaum <mwlochbaum@gmail.com> | 2022-05-28 21:55:15 -0400 |
| commit | 18d1bce85de22f8bc7a08453618c7d9e94b61f92 (patch) | |
| tree | 87226d2fe5238c87079520db1a4f052740382f1c /doc | |
| parent | bd4209a653a68929a9fb1a215bbc3e34a393e753 (diff) | |
Editing
Diffstat (limited to 'doc')
| -rw-r--r-- | doc/hook.md | 12 | ||||
| -rw-r--r-- | doc/identity.md | 15 |
2 files changed, 8 insertions, 19 deletions
diff --git a/doc/hook.md b/doc/hook.md index 368d3854..94b301d3 100644 --- a/doc/hook.md +++ b/doc/hook.md @@ -19,7 +19,7 @@ The "hook" combinators Before and After serve a few purposes in BQN. The importa ## Description -In the general case, I think of Before as using `𝔽` as a preprocessing function applied to `𝕨` (when there are two arguments) and After as using `𝔾` as preprocessing for `𝕩`. Then the other operand is called on the result and remaining argument. Here are some simple calls with Pair (`⋈`): the result is a pair that corresponds to `𝕨‿𝕩`, but one or the other result has been modified by the pointy-side function. +In the general case, I think of Before as using `𝔽` as a preprocessing function applied to `𝕨` (when there are two arguments), and After as using `𝔾` as preprocessing for `𝕩`. Then the other operand is called on the result and remaining argument. Here are some simple calls with [Pair](pair.md) (`⋈`): the result is a pair that corresponds to `𝕨‿𝕩`, but one or the other result has been modified by the pointy-side function. 9 √⊸⋈ 2 @@ -33,7 +33,7 @@ This can be used to make a "filter" pattern using [Replicate](replicate.md) (`/` {𝕩<0}¨⊸/ 4‿¯2‿1‿¯3‿¯3 -As `<` is a pervasive function, there's no need for the Each (`¨`) in this case, and the clunky block function `{𝕩<0}` can also be written smaller with a combinator, as `<⟜0`. More on that in the next section… +As `<` is a [pervasive](arithmetic.md#pervasion) function, there's no need for the Each (`¨`) in this case, and the clunky block function `{𝕩<0}` can also be written smaller with a combinator, as `<⟜0`. More on that in the next section… <⟜0⊸/ 4‿¯2‿1‿¯3‿¯3 @@ -43,7 +43,7 @@ As `<` is a pervasive function, there's no need for the Each (`¨`) in this case <⟜0 4‿¯2‿1‿¯3‿¯3 -If we expand `<⟜0 x`, we get `x < (0 x)`, which doesn't quite make sense. That's because `0` has a subject role, but `⟜` always applies its operands as functions. It's more accurate to use `x < (0{𝔽} x)`, or just skip ahead to `x < 0`. +If we expand `<⟜0 x`, we get `x < (0 x)`, which doesn't quite make sense. That's because `0` has a subject [role](expression.md#syntactic-role), but `⟜` always applies its operands as functions. It's more accurate to use `x < (0{𝔽} x)`, or just skip ahead to `x < 0`. Similar reasoning gives the following expansions: @@ -54,7 +54,7 @@ Similar reasoning gives the following expansions: Note that when there are two arguments, the constant "swallows" the one on the same side, so that the function is applied to the constant and the argument on the *opposite* side. -As in a train, if you want to use a function as a constant then you need to be explicity about it, with the [Constant](constant.md) (`˙`) modifier. +As in a train, if you want to use a function as a constant then you need to be explicit about it, with the [Constant](constant.md) (`˙`) modifier. 3 ⋈⟜(⌊˙)⊸⥊ 'a'+↕12 @@ -64,7 +64,7 @@ In the more extreme case of wanting a *modifier* operand, you might try `⋈⟜( If you like to go [tacit](tacit.md), 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 `F⊸G⟜H`, the ordering doesn't matter at all! That is, it means `(F⊸G)⟜H`, but this is exactly the same function as `F⊸(G⟜H)`. In both cases, `F` is applied to `𝕨`, `H` is applied to `𝕩`, and `G` acts on both the results. +In the pattern `F⊸G⟜H`, the ordering doesn't matter at all! That is, it means `(F⊸G)⟜H`, but this is the same function as `F⊸(G⟜H)`. In both cases, `F` is applied to `𝕨`, `H` is applied to `𝕩`, and `G` acts on both the results (the parentheses do change whether `F` or `H` is called first, which only matters if they have side effects). 4 -⊸⋈⟜⋆ 2 @@ -88,4 +88,4 @@ Here's a long example, that might show up if you want to [sort](order.md#sort) a (⌊≠÷2˙)⊸⊑⊸≤⊸⊔ "quicksort" # Use to partition 𝕩 -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](../README.md). I think a combination like `lots∘of○stuff⊸/ 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. +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](../README.md). I think a combination like `lots∘of○stuff⊸/ x` reads very nicely when moving from right to left. When I see `⊸/` I know that I'm filtering `x` and can read the rest with that context. The reason `⊸` 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. diff --git a/doc/identity.md b/doc/identity.md index e8682ea5..648fe466 100644 --- a/doc/identity.md +++ b/doc/identity.md @@ -12,7 +12,7 @@ Here are the simplest functions in BQN: Right (`⊢`) always returns its right a "left" ⊣ "right" -Depending on your past experiences, this could cause some confusion: built-in support for functions that do nothing? Documentation should say why a feature's there and how to use it, not just what it does, so we'll try to address this below. The most important single use is for tacit programming, but there are a variety of other uses as well. +Depending on your past experiences, this could cause some confusion: built-in support for functions that do nothing? Documentation should say why a feature's there and how to use it, not just what it does, so we'll try to address this below. The most important single use is for [tacit](tacit.md) programming, but there are a variety of other uses as well. Of course, it's easy to write block functions `{𝕩}` and `{𝕨}` that return particular arguments. While I would already make `⊣` and `⊢` primitives just because they are common and important, there are also specific disadvantages to using blocks. They fail to indicate that there are no side effects, as primitives would, and they also need special casing for the interpreter to manipulate them when applying [Undo](undo.md) (`⁼`) or making other inferences. @@ -51,19 +51,8 @@ In a [tacit](tacit.md) context, `⊣` is roughly equivalent to `𝕨` and `⊢` A larger class of block functions can be translated just by adding parentheses and `˙` (there's a discussion of this technique in APL [here](https://dfns.dyalog.com/n_tacit.htm)). It's helpful when writing tacit code to know that `Fn∘⊣` applies `Fn` to the left argument only and `Fn∘⊢` applies it to the right argument—these can be read "Fn of left" and "Fn of right". -## Syntax tricks +## One more thing You've probably seen `⊢` used in documentation to display the value of a variable being assigned. This is a hack, and in most contexts `•Show` should be used to display values. ⊢ a ← "show this" - -More importantly, `∘⊣` can be used to ignore a right argument for modified assignment, to apply a function "in place" to a variable without writing the variable name twice. - - a ⌽∘⊣↩ @ - -In APL a tack can be used to avoid stranding numbers together. In BQN, stranding is explicit, and there's no need! - - ÷⟜2⍟3⊢ 24 - ÷⟜2⍟3 24 - -(Wow, what a useless section.) |
