View this file with results and syntax highlighting here.
Constant
It's one of the simple ones: fΛπ© is f. And π¨fΛπ©? It's f. Like the identity functions, Constant doesn't compute anything but just returns one of its inputs. It's somewhat different in that it's a deferred modifier, so you have to first apply Constant to its operand and then to some arguments for that non-event to happen.
The design of BQN makes Constant unnecessary in most cases, because when a non-operation (number, character, array, namespace) is applied it already returns itself: ΟΛ is the same function as Ο. If you've used much tacit programming, you've probably written a few trains like 2Γ+ (twice the sum), which is nicer than the equivalent 2ΛΓ+. However, a train has to end with a function, so you can't just put a number at the end. Applying Λ is a convenient way to change the number from a subject to a function role.
+Γ·2 # A number
+Γ·2Λ # A function
3 (+Γ·2Λ) 7
When programming with first-class functions, the constant application shortcut becomes a hazard! Consider the program {π¨βΎ(2βΈβ) π©} to insert π¨ into an array π© as an element. It works fine with a number, but with a function it's broken:
β {π¨βΎ(2βΈβ) π©} 1βΏ2βΏ3βΏ4
M β -
m {π¨βΎ(2βΈβ) π©} 1βΏ2βΏ3βΏ4
Here m is applied to 2βπ© even though we want to discard that value. Spelled as m, our context-free grammar knows it's a function argument, but this doesn't affect later usage. Under always applies π½ as a function. The proper definition of the insertion function should use a Λ, like this:
m {π¨ΛβΎ(2βΈβ) π©} 1βΏ2βΏ3βΏ4
