diff options
| author | Marshall Lochbaum <mwlochbaum@gmail.com> | 2020-06-07 12:22:32 -0400 |
|---|---|---|
| committer | Marshall Lochbaum <mwlochbaum@gmail.com> | 2020-06-07 12:22:32 -0400 |
| commit | d8160481548f9b9bff2e43c4d5f825b388a1e85e (patch) | |
| tree | 4d3f64ffd381def4c317a86b9e88f656589058e9 | |
| parent | 60d59965f6df613a8cc95aa8bd18823945734d69 (diff) | |
Cover the rest of the glyphs
| -rw-r--r-- | README.md | 59 |
1 files changed, 56 insertions, 3 deletions
@@ -30,15 +30,19 @@ It looks like qebrus okay: ## Syntax +BQN syntax consists of expressions where computation is done with a little organizing structure around them like assignment, functions, and list notation. Expressions are where the programmer is in control so the design tries to do as much as possible with them before introducing special syntax. + +### Expressions + Like APL, BQN values have one of four *syntactic classes*: * **Values**, like APL arrays or J nouns * **Functions**, or verbs in J * **Modifiers**, like APL monadic operators or J adverbs -* **Combinators**, like APL dyadic operators or J conjunctions. +* **Compositions**, like APL dyadic operators or J conjunctions. -These classes work exactly like they do in APL, with functions applying to one or two arguments, modifiers taking a single function or value on the left, and combinators taking a function or value on each side. +These classes work exactly like they do in APL, with functions applying to one or two arguments, modifiers taking a single function or value on the left, and compositions taking a function or value on each side. -Unlike APL, in BQN the syntactic class of a value is determined purely by the way it's spelled: a lowercase first letter (`name`) makes it a value, an uppercase first letter (`Name`) makes it a function, and underscores are used for modifiers (`_name`) and combinators (`_name_`). Below, the function `{ππ©}` treats its left argument `π` as a function and its right argument `π©` as an argument. With a list of functions, we can make a table of the square and square root of a few numbers: +Unlike APL, in BQN the syntactic class of a value is determined purely by the way it's spelled: a lowercase first letter (`name`) makes it a value, an uppercase first letter (`Name`) makes it a function, and underscores are used for modifiers (`_name`) and compositions (`_name_`). Below, the function `{ππ©}` treats its left argument `π` as a function and its right argument `π©` as an argument. With a list of functions, we can make a table of the square and square root of a few numbers: β¨ΓΛ,ββ© {ππ©}β 1βΏ4βΏ9 β @@ -46,6 +50,29 @@ Unlike APL, in BQN the syntactic class of a value is determined purely by the wa 1 2 3 β +BQN's built-in operations also have patterns to indicate the syntactic class: modifiers (`` ΛΒ¨ΛβΌβΒ΄` ``) are all superscript characters, and compositions (`βββΈββΎβββ`) all have an unbroken circle (two functions `β½β` have broken circles with lines through them). Every other built-in constant is a function, although the special symbols `Β―`, `β`, and `Ο` are used as part of numeric literal notation. + +### Special syntax + +Most of these glyphs are explained further in the section on [literal notation](#Literal notation). + +Glyph(s) | Meaning +----------------|----------- +`β` | Define +`β©` | Modify +`β` | Return +`β,` or newline | Statement or element separator +`()` | Expression grouping +`{}` | Explicit function, modifier, or composition +`β¨β©` | List/vector +`βΏ` | Strand (lightweight vector syntax) +`β¦β¦` | Set +`π¨π` | Left argument +`π©π` | Right argument +`ππ½` | Left operand (modifier or composition) +`ππΎ` | Right operand (composition) +`β` | Comment + ## Built-in operations ### Functions @@ -93,3 +120,29 @@ Unlike APL, in BQN the syntactic class of a value is determined purely by the wa | `β` | Unique Mask | Member of | `β·` | | Find | `β` | Group | Key + +### Modifiers and compositions + +*Combinators* only control the application of functions. Because a non-function operand applies as a constant function, some combinators have extra meanings when passed a constant. For example, `0Λ` is the constant function that always returns 0 and `0βΈ<` is the function that tests whether its right argument is greater than 0. + +Glyph | Name(s) | Definition | Description +------|-------------|--------------------------------|--------------------------------------- +`Λ` | Self/Swap | `{π©π½π¨β£π©}` | Duplicate one argument or exchange two +`β` | Atop | `{π½π¨πΎπ©}` | Apply πΎ to both arguments and π½ to the result +`β` | Over | `{(πΎπ¨)π½πΎπ©}` | Apply πΎ to each argument and π½ to the results +`βΈ` | Before/Bind | `{(π½π¨)πΎπ©}ΛΛ` | πΎ's left argument comes from π½ +`β` | After/Bind | `{π¨π½πΎπ©}ΛΛ` | π½'s right argument comes from πΎ +`βΎ` | Under | `{πΎβΌβπ½βπΎ}` OR `{(πΎπ©)βπ¨π½βπΎπ©βπ©}` | Apply π½ over πΎ, then undo πΎ + +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). + +Other modifiers and compositions control array traversal and iteration. In three cases a simpler modifier is paired with a generalized composition: in each case the modifier happens to be the same as the composition with a right operand of `Β―1`. + +Modifier | Name | Compositon | Name +---------|---------|------------|-------- +`Λ` | Cells | β | Rank +`Β¨` | Each | β | Depth +`β` | Table | +`βΌ` | Inverse | β | Iterate +`Β΄` | Reduce | +`` ` `` | Scan | |
