Have the arguments to a function, but not in the right places? Self/Swap (Λ) will fix it for you. There are only two APL-style 1-modifiersβthat is, operands used as functions and applied to argumentsβthat make sense, and Λ is both of them. It always calls its operand with two arguments: if there are two arguments to begin with, they are exchanged (Swap), and if there's only one, it's used for both arguments (Self).
| Name | Call | Definition |
|---|---|---|
| Self | FΛπ© |
π©Fπ© |
| Swap | π¨FΛπ© |
π©Fπ¨ |
Since π© is always the left argument, these two definitions can be unified as {π©π½π¨β£π©}, noting that Left becomes a plain identity function when the left argument π¨ isn't given.
Swap is arguably less transformative. Some common examples are -Λ and Γ·Λ, since these two functions run the wrong way for BQN's evaluation order. This is very often useful in tacit programming, and less useful for explicit code. While it sometimes allows for shorter code by making a pair of parentheses unnecessary (say, (aΓb)-c is c-ΛaΓb), I personally don't think this is always a good idea. My opinion is that it should be used when it makes the semantics a better fit for BQN, but putting the primary argument on the right and a secondary or control argument on the left.
'a' βΛ 'b' "ba" " +" βΛ 0βΏ1βΏ1βΏ0βΏ0β1βΏ0βΏ1βΏ0βΏ1 ββ β΅" ++ + + +" β
Self re-uses one argument twice. In this way it's a little like Over, which re-uses one function twice. A common combination is with Table, βΛ, so that the operand function is called on each combination of elements from the argument to form a square result. For example, =βΛ applied to βn gives the identity matrix of size n.
ΓΛ 4 16 =βΛ β3 ββ β΅ 1 0 0 0 1 0 0 0 1 β
Note that Self isn't needed with Before (βΈ) and After (β), which essentially have a copy built in: for example FβΈG π© is the same as FβΈGΛ π© by definition.