*View this file with results and syntax highlighting [here](https://mlochbaum.github.io/BQN/doc/tacit.html).* # Tacit programming [Tacit programming](https://aplwiki.com/wiki/Tacit_programming) (or "point-free" in some other languages) is a term for defining functions without referring to arguments directly, which in BQN means programming without [blocks](block.md). Instead, tacit programs are built up by combining smaller functions together; we'll discuss the ways BQN offers to combine functions on this page. Since primitive functions like those returning the left (`⊣`) and right (`⊢`) arguments, and selection functions (`⊏⊑`), are available as building blocks, tacit programming doesn't keep the programmer from pinpointing a specific part of the input, as the description might lead you to believe. Nonetheless, it has its limitations. In larger tacit programs, moving values to the right place is tedious and error-prone because of the lack of a convenient labelling mechanism, and important context tends to disappear in a sea of symbols. In smaller amounts—portions of a line—tacit programming can be the clearest way to express an idea, particularly when just one or two variables are used a few times. Consider the following three expressions to filter only the positive values from a list: l ← 0‿5‿¯2‿1‿¯3‿¯4 (0 Each of these combinators has its role to play in tacit code. To start with, [Constant](constant.md) (`˙`) is the subtlest one, because it's used everywhere, in a sense, but rarely needs to be made explicit. This is because data values already behave like constant functions. For example, the train `4+×` might more precisely be written `4˙+×`, but trains conveniently handle this part already. However, it *is* often used at the end of a train, to force the last part into a function role. `×-1` isn't a train—it just evaluates to ¯1. But `×-1˙` is the train that multiplies its arguments and subtracts 1. Using [Self and Swap](swap.md) is pretty straightforward. Swap in particular is often useful if your arguments happen to be the wrong way around. For example, `⌊∘÷˜⋈|` gives you the integer part and remainder when dividing `𝕨` by `𝕩`. For compatibility with math, `÷` is "backwards" from a BQN perspective, but `˜` will fix that right up. And while we're at it, let's note that [Atop](compose.md#atop) is just another way to write a 2-train, so that `⌊∘÷˜` is `(⌊÷)˜` but avoids the parentheses. 3 (⌊∘÷˜⋈|) 13 # 13 = 1+3×4 [Before and After](hook.md) are tacit powerhouses. Yes, `F⊸G` is just `F∘⊣G⊢` and `G⟜F` is `⊣G F∘⊢`. But the symmetric symbols make these cases a lot easier to read and manipulate as a programmer (just remember, pointy-side function is applied first!). It's common to write big tacit functions with the pattern `(…)⊸Fn 𝕩`, so a lot of processing is applied to `𝕩` and then the result of this is passed along with `𝕩` to `Fn`. And of course binds like `÷⟜2`, dividing by 2, or `¯1⊸»`, shifting in a ¯1, are very often helpful. [Over](compose.md#over) is a bit weirder, and you'll have to learn when to recognize this pattern (of course, a repeated function is a strong hint). Perhaps you'd compare the first element of two lists with `≡○⊑`, for example. ## Conditionals There are two main ways to perform conditional logic in tacit code. Although, a note first: for arithmetic, array operations that use booleans as numbers can often fill in for conditionals, and they're a lot faster. So, to replace every space character with a hyphen, try this function that multiplies the difference between those characters by a mask that's 1 where `𝕩` is a space, then subtracts that back from `𝕩`. " -" (⊢--´∘⊣×⊑⊸=) "ab cde f " The [Repeat](repeat.md) (`⍟`) modifier makes a nice "if" conditional. `F⍟G`, assuming the result of `G` is a boolean, is equivalent to `{𝕨G𝕩?𝕨F𝕩;𝕩}`. Note how `𝕨` gets passed in to both functions. Often you'll want `𝔽` to apply to `𝕩` only, and in this case, you need to make this explicit with `⊢` or similar. 3 (2÷˜⊢)⍟< 7 # halve 𝕩 if greater than 𝕨 For more complicated "if-else" or "select" type conditionals, use [Choose](choose.md) (`◶`). Watch for ordering here: `F◶⟨G0,G1⟩` puts the two parts in the opposite order to Repeat, and list element 1 comes after element 0 even though it might seem more intuitive for the "true" value to come first.