From 2528ec5e75daa358162619cc3a704e6bdf88a2c8 Mon Sep 17 00:00:00 2001 From: Marshall Lochbaum Date: Thu, 14 Apr 2022 21:45:05 -0400 Subject: Documentation for Valences --- doc/README.md | 1 + doc/combinator.bqn | 2 +- doc/primitive.md | 2 +- doc/valences.md | 19 +++++++++++++++++++ 4 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 doc/valences.md (limited to 'doc') diff --git a/doc/README.md b/doc/README.md index 26374f5c..8acd5740 100644 --- a/doc/README.md +++ b/doc/README.md @@ -71,6 +71,7 @@ Primitives: - [Take and Drop](take.md) (`↑`) - [Transpose](transpose.md) (`⍉`) - [Undo](undo.md) (`⁼`) +- [Valences](valences.md) (`⊘`) - [Windows](windows.md) (`↕`) Environment: diff --git a/doc/combinator.bqn b/doc/combinator.bqn index fa4466f7..e16dc5a9 100644 --- a/doc/combinator.bqn +++ b/doc/combinator.bqn @@ -4,7 +4,7 @@ w‿h ← 280‿260 Pnt ← 32‿57×⌽ comps ← "∘○˙⊸⟜˜⊘" -names ← (¬×+`)⊸-∘=⟜' '⊸⊔ "Atop Over Constant Before After Self/Swap Cases" +names ← (¬×+`)⊸-∘=⟜' '⊸⊔ "Atop Over Constant Before After Self/Swap Valences" ps ← At "class=yellow|style=fill:none|stroke-width=2" _trans ← {𝕗 At "transform=translate("∾(⊣∾","∾⊢)○FmtNum∾")"˙} diff --git a/doc/primitive.md b/doc/primitive.md index c358d80a..b1253e3c 100644 --- a/doc/primitive.md +++ b/doc/primitive.md @@ -74,7 +74,7 @@ Glyph | Name(s) | Definition | Description `⊸` | Before/Bind | `{(𝔽𝕨⊣𝕩)𝔾𝕩}` | `𝔾`'s left argument comes from `𝔽` `⟜` | After/Bind | `{(𝕨⊣𝕩)𝔽𝔾𝕩}` | `𝔽`'s right argument comes from `𝔾` `⌾` | Under | `{𝔾⁼∘𝔽○𝔾}` OR `{(𝔾𝕩)↩𝕨𝔽○𝔾𝕩⋄𝕩}` | Apply `𝔽` over `𝔾`, then undo `𝔾` -`⊘` | Valences | `{𝔽𝕩;𝕨𝔾𝕩}` | Apply `𝔽` if there's one argument but `𝔾` if there are two +`⊘` | [Valences](valences.md) | `{𝔽𝕩;𝕨𝔾𝕩}` | Apply `𝔽` if there's one argument but `𝔾` if there are two `◶` | Choose | `{f←(𝕨𝔽𝕩)⊑𝕘 ⋄ 𝕨F𝕩}` | Select one of the functions in list `𝕘` based on `𝔽` Choose isn't really a combinator since it calls the function `⊑`, and Under is not a true combinator since it has an "undo" step at the end. This step might be implemented using the left operand's inverse (*computational* Under) or its structural properties (*structural* Under). diff --git a/doc/valences.md b/doc/valences.md new file mode 100644 index 00000000..7c2c9d59 --- /dev/null +++ b/doc/valences.md @@ -0,0 +1,19 @@ +*View this file with results and syntax highlighting [here](https://mlochbaum.github.io/BQN/doc/valences.html).* + +# Valences + + + +Every BQN function can be called with one or two arguments, possibly doing completely different things in each case. The Valences (`⊘`) 2-modifier grafts together a one-argument function `𝔽` and a two-argument function `𝔾`, with the resulting function calling one or the other as appropriate. It's the [tacit](tacit.md) equivalent of a block function with [two bodies](block.md#multiple-bodies). So the function `{÷𝕩 ; 𝕩-𝕨}` can also be written `÷⊘(-˜)`. A full definition of Valences as a block is `{𝔽𝕩;𝕨𝔾𝕩}`. + + -⊘+ 6 # - side + + 3 -⊘+ 2 # + side + +Valences provides one way to check whether `𝕨` is present in a block function. The expression `𝕨0⊘1𝕩` always ignores the values of the arguments, resulting in `0` if `𝕨` isn't given and `1` if it is (if you want `1` or `2`, then `≠𝕨⋈𝕩` is shorter, but I'm not sure if I like it). + + {𝕨0⊘1𝕩} 'x' + + 'w' {𝕨0⊘1𝕩} 'x' -- cgit v1.2.3