blob: 7c2c9d592298d9ded5d181fccbe45872db85f4c7 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
*View this file with results and syntax highlighting [here](https://mlochbaum.github.io/BQN/doc/valences.html).*
# Valences
<!--GEN combinator.bqn
DrawComp β"β"
-->
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'
|