From 93f75e97685520cdad3afab0134e2f65e5e211e2 Mon Sep 17 00:00:00 2001 From: Marshall Lochbaum Date: Tue, 21 Jul 2020 19:48:24 -0400 Subject: =?UTF-8?q?Add=20Insert=20(=CB=9D)=201-modifier?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 1 + c.bqn | 10 +++++----- doc/context.md | 2 +- doc/fromDyalog.md | 8 ++++---- doc/group.md | 6 +++--- doc/transpose.md | 2 +- doc/windows.md | 4 ++-- docs/doc/context.html | 2 +- docs/doc/fromDyalog.html | 8 ++++---- docs/doc/group.html | 6 +++--- docs/doc/transpose.html | 2 +- docs/doc/windows.html | 4 ++-- docs/index.html | 6 ++++++ docs/problems.html | 16 ++++++++-------- docs/spec/token.html | 2 +- dzref | 13 +++++++++---- examples/fifty.bqn | 6 +++--- md.bqn | 10 +++++----- problems.md | 16 ++++++++-------- spec/reference.bqn | 11 ++++++++--- spec/token.md | 2 +- 21 files changed, 77 insertions(+), 60 deletions(-) diff --git a/README.md b/README.md index 84e8c0a1..2555acd8 100644 --- a/README.md +++ b/README.md @@ -159,6 +159,7 @@ Other modifiers control array traversal and iteration. In three cases a simpler `⌜` | Table | `⁼` | Undo | `⍟` | Repeat `´` | Reduce | +`˝` | Insert | `` ` `` | Scan | ## Literal notation diff --git a/c.bqn b/c.bqn index 13252655..30525216 100755 --- a/c.bqn +++ b/c.bqn @@ -3,7 +3,7 @@ nl‿tab←•UCS 10‿9 charSet←∾charGroups←⟨ chF←"+-×÷⋆√⌊⌈|¬∧∨<>≠=≤≥≡≢⊣⊢⥊∾≍↑↓↕⌽⍉/⍋⍒⊏⊑⊐⊒∊⍷⊔!" # Function - "˜˘¨⌜⁼´`" # Modifier + "˜˘¨⌜⁼´˝`" # Modifier "∘○⊸⟜⌾⊘◶⎉⚇⍟" # Composition ¯1⊏˘10‿2⥊"𝕨𝕎𝕩𝕏𝕗𝔽𝕘𝔾𝕤𝕊" # Input (𝕣 pending; ℝ not allowed) nl∾"⋄," # Separator @@ -79,7 +79,7 @@ GenF64←{ l←2(⌊⋆⁼)𝕩 (Hex"44")∾2 Base˘8‿8⥊∾⟨¯52↑(0⌈l)Enc2𝕩,11 Enc2 1023+l,⥊0⟩ } -MakeTab←{{⊑∘(∾⟜0)¨¯1↓(chF⊐𝕨)⊔○(∾⟜(≠chF))𝕩}○∾⟜(⥊¨∘⥊¨)´<˘⍉(2(÷˜∾⊣)≢)⊸⥊𝕩} +MakeTab←{{⊑∘(∾⟜0)¨¯1↓(chF⊐𝕨)⊔○(∾⟜(≠chF))𝕩}○∾⟜(⥊¨∘⥊¨)˝⍉(2(÷˜∾⊣)≢)⊸⥊𝕩} tab1←MakeTab⟨ "⊣⊢" , 2⥊<⟨⟩ "|-⌈⌊√" , (Hex"99")+(↕4)∾6 @@ -98,7 +98,7 @@ f64←127-3 GenFn←{ ⟨⟩GenFn𝕩; ⟨t,r,nVar,nLoc,lits⟩←𝕨Tokenize𝕩 - t⊏˜↩⍋+`-´<˘(2‿3⊏bB)=⌜t + t⊏˜↩⍋+`-˝(2‿3⊏bB)=⌜t nd←+´c←t=3⊑bB t↩((vi+nVar+≠lits)+↕∘≠)⌾(c⊸/)t ⟨a,na⟩←Parse t @@ -111,7 +111,7 @@ GenFn←{ } Gen←{ - LEB←{0:⥊0;128⊸+⌾(¯1⊸↓) 2 Base˘ (⌽·∨`·⌽∨´˘)⊸/ 10‿7(⊣⥊×´⊸↑) 64 Enc2 𝕩} + LEB←{0:⥊0;128⊸+⌾(¯1⊸↓) 2 Base˘ (∨`⌾⌽∨˝˘)⊸/ 10‿7(⊣⥊×´⊸↑) 64 Enc2 𝕩} C←LEB∘≠⊸∾ S←∾⟜C V←≠∾∾ @@ -163,7 +163,7 @@ DParse ← {nv‿r𝕊𝕩: prims←⟨ +,-,×,÷,⋆,√,⌊,⌈,|,¬,∧,∨,<,>,≠,=,≤,≥,≡,≢,⊣,⊢,⥊,∾,≍,↑,↓,↕,⌽,⍉,/,⍋,⍒,⊏,⊑,⊐,⊒,∊,⍷,⊔,! - ˜,˘,¨,⌜,⁼,´,` + ˜,˘,¨,⌜,⁼,´,˝,` ∘,○,⊸,⟜,⌾,⊘,◶,⎉,⚇,⍟ ⟩ DGenFn←{ diff --git a/doc/context.md b/doc/context.md index fe800cfa..bf2183bb 100644 --- a/doc/context.md +++ b/doc/context.md @@ -38,7 +38,7 @@ BQN's expression grammar is a simplified version of the typical APL, removing so | 1-modifier | Monadic operator | Adverb | 2-modifier | Dyadic operator | Conjunction -Unlike variables, BQN primitives have only one spelling, and a fixed role (but their values can be used in a different role by storing them in variables). Superscript glyphs `` ˜¨˘⁼⌜´` `` are used for 1-modifiers, and glyphs `∘○⊸⟜⌾⊘◶⚇⎉⍟` with an unbroken circle are 2-modifiers. Other primitives are functions. String and numeric literals are subjects. +Unlike variables, BQN primitives have only one spelling, and a fixed role (but their values can be used in a different role by storing them in variables). Superscript glyphs `` ˜¨˘⁼⌜´˝` `` are used for 1-modifiers, and glyphs `∘○⊸⟜⌾⊘◶⚇⎉⍟` with an unbroken circle are 2-modifiers. Other primitives are functions. String and numeric literals are subjects. BQN's variables use another system, where the spelling indicates how the variable's value is used. A variable spelled with a lowercase first letter, like `var`, is a subject. Spelled with an uppercase first letter, like `Var`, it is a function. Underscores are placed where operands apply to indicate a 1-modifier `_var` or 2-modifier `_var_`. Other than the first letter or underscore, variables are case-insensitive. diff --git a/doc/fromDyalog.md b/doc/fromDyalog.md index 3eaf752d..2f4e5aae 100644 --- a/doc/fromDyalog.md +++ b/doc/fromDyalog.md @@ -20,7 +20,7 @@ Here are some closest equivalents in Dyalog APL for the BQN functions that don't Modifiers are a little harder. Many have equivalents in some cases, but Dyalog sometimes chooses different functionality based on whether the operand is an array. In BQN an array is always treated as a constant function. -| BQN | `¨` | `⌜` | `´` | `⎉` | `⍟` | `˜` | `∘` | `○` | `⟜` | +| BQN | `¨` | `⌜` | `˝` | `⎉` | `⍟` | `˜` | `∘` | `○` | `⟜` | |--------|-----|------|-----|-----|-----|-----|-----|-----|-----| | Dyalog | `¨` | `∘.` | `⌿` | `⍤` | `⍣` | `⍨` | `⍤` | `⍥` | `∘` | @@ -62,19 +62,19 @@ The tables below give approximate implementations of Dyalog primitives for the o {+⟜(𝕨⊸×)´⌽𝕩} {𝕨|1↓⌊∘÷`⌾⌽𝕨∾<𝕩} - +´∘×⎉1‿∞⁼ I guess + +˝∘×⎉1‿∞⁼ I guess N/A - + - + diff --git a/doc/group.md b/doc/group.md index dcf13220..e043e5ca 100644 --- a/doc/group.md +++ b/doc/group.md @@ -103,6 +103,6 @@ In other cases, we might want to split on spaces, so that words are separated by However, trailing spaces are ignored because Group never produces trailing empty groups (to get them back we would use a dummy final character in the string). To avoid empty words, we should increase the word index only once per group of spaces. We can do this by taking the prefix sum of a list that is 1 only for a space with no space before it. To make such a list, we can use the [Windows](windows.md) function. We will extend our list with an initial 1 so that leading spaces will be ignored. Then we take windows of the same length as the original list: the first includes the dummy argument followed by a shifted copy of the list, and the second is the original list. These represent whether the previous and current characters are spaces; we want positions where the previous wasn't a space and the current is. - ≍⟜((<´<˘)≠↕1∾⊢) ' '=" string with spaces " # All, then filtered, spaces - ≍⟜(⊢-˜¬×+`∘((<´<˘)≠↕1∾⊢))' '=" string with spaces " # More processing - ' '((⊢-˜¬×+`∘((<´<˘)≠↕1∾⊢))∘=⊔⊢)" string with spaces " # Final result + ≍⟜(<˝≠↕1∾⊢) ' '=" string with spaces " # All, then filtered, spaces + ≍⟜(⊢-˜¬×+`∘(<˝≠↕1∾⊢))' '=" string with spaces " # More processing + ' '((⊢-˜¬×+`∘(<˝≠↕1∾⊢))∘=⊔⊢)" string with spaces " # Final result diff --git a/doc/transpose.md b/doc/transpose.md index 3e7bf5c3..21628dcd 100644 --- a/doc/transpose.md +++ b/doc/transpose.md @@ -6,7 +6,7 @@ As in APL, Transpose (`⍉`) is a tool for rearranging the axes of an array. BQN ## Monadic Transpose -Transposing a matrix exchanges its axes, mirroring it across the diagonal. APL extends the function to any rank by reversing all axes, but this generalization isn't very natural and is almost never used. The main reason for it is to maintain the equivalence `a MP b ←→ a MP⌾⍉ b`, where `MP ← (+´<˘)∘×⎉1‿∞` is the generalized matrix product. But even here APL's Transpose is suspect. It does much more work than it needs to, as we'll see. +Transposing a matrix exchanges its axes, mirroring it across the diagonal. APL extends the function to any rank by reversing all axes, but this generalization isn't very natural and is almost never used. The main reason for it is to maintain the equivalence `a MP b ←→ a MP⌾⍉ b`, where `MP ← +˝∘×⎉1‿∞` is the generalized matrix product. But even here APL's Transpose is suspect. It does much more work than it needs to, as we'll see. BQN's transpose takes the first axis of its argument and moves it to the end. diff --git a/doc/windows.md b/doc/windows.md index a60e1ae0..2f1eda55 100644 --- a/doc/windows.md +++ b/doc/windows.md @@ -68,8 +68,8 @@ Windows can be followed up with a reduction on each slice to give a windowed red A common task is to pair elements, with an initial or final element so the total length stays the same. This can also be done with a pairwise reduction, but another good way (and more performant without special support in the interpreter) is to add the element and then use windows matching the original length. Here both methods are used to invert `` +` ``, which requires we take pairwise differences starting at initial value 0. -˜´˘2↕0∾ +` 3‿2‿1‿1 - ((-˜´<˘)≠↕0∾⊢) +` 3‿2‿1‿1 + (-˜˝≠↕0∾⊢) +` 3‿2‿1‿1 This method extends to any number of initial elements. We can modify the running sum above to keep the length constant by starting with two zeros. - ((+´<˘)≠↕(2⥊0)⊸∾) ⟨2,6,0,1,4,3⟩ + (+˝≠↕(2⥊0)⊸∾) ⟨2,6,0,1,4,3⟩ diff --git a/docs/doc/context.html b/docs/doc/context.html index b4c5616f..8d108e5f 100644 --- a/docs/doc/context.html +++ b/docs/doc/context.html @@ -50,7 +50,7 @@
Operators
Syntax Monadic Dyadic
´
¨˝
or `
¨ ¨
˜
f.g (f´<˘)∘g⎉1‿∞
f.g f˝∘g⎉1‿∞
∘.f f⌜
A∘g A⊸g
f∘B f⟜B
-

Unlike variables, BQN primitives have only one spelling, and a fixed role (but their values can be used in a different role by storing them in variables). Superscript glyphs ˜¨˘⁼⌜´` are used for 1-modifiers, and glyphs ∘○⊸⟜⌾⊘◶⚇⎉⍟ with an unbroken circle are 2-modifiers. Other primitives are functions. String and numeric literals are subjects.

+

Unlike variables, BQN primitives have only one spelling, and a fixed role (but their values can be used in a different role by storing them in variables). Superscript glyphs ˜¨˘⁼⌜´˝` are used for 1-modifiers, and glyphs ∘○⊸⟜⌾⊘◶⚇⎉⍟ with an unbroken circle are 2-modifiers. Other primitives are functions. String and numeric literals are subjects.

BQN's variables use another system, where the spelling indicates how the variable's value is used. A variable spelled with a lowercase first letter, like var, is a subject. Spelled with an uppercase first letter, like Var, it is a function. Underscores are placed where operands apply to indicate a 1-modifier _var or 2-modifier _var_. Other than the first letter or underscore, variables are case-insensitive.

The associations between spelling and syntactic role are considered part of BQN's token formation rules.

One rule for typing is also best considered to be a pre-parsing rule like the spelling system: the role of a brace construct {} with no header is determined by which special arguments it uses: it's a subject if there are none, but a 𝕨 or 𝕩 makes it at least a function, an 𝔽 makes it a 1- or 2-modifier, and a 𝔾 always makes it a 2-modifier.

diff --git a/docs/doc/fromDyalog.html b/docs/doc/fromDyalog.html index 0b9ca972..ec02f2e7 100644 --- a/docs/doc/fromDyalog.html +++ b/docs/doc/fromDyalog.html @@ -116,7 +116,7 @@ BQN ¨ -´ +˝ ˜ @@ -175,19 +175,19 @@ {+(𝕨×)´𝕩} {𝕨|1↓⌊÷`𝕨∾<𝕩} - +´×1 I guess + +˝×1 I guess N/A - + - + diff --git a/docs/doc/group.html b/docs/doc/group.html index 590b166b..2ec68f63 100644 --- a/docs/doc/group.html +++ b/docs/doc/group.html @@ -138,17 +138,17 @@ ⟨ ⟨⟩ ⟨⟩ "string" "with" ⟨⟩ "spaces" ⟩

However, trailing spaces are ignored because Group never produces trailing empty groups (to get them back we would use a dummy final character in the string). To avoid empty words, we should increase the word index only once per group of spaces. We can do this by taking the prefix sum of a list that is 1 only for a space with no space before it. To make such a list, we can use the Windows function. We will extend our list with an initial 1 so that leading spaces will be ignored. Then we take windows of the same length as the original list: the first includes the dummy argument followed by a shifted copy of the list, and the second is the original list. These represent whether the previous and current characters are spaces; we want positions where the previous wasn't a space and the current is.

-
    ((<´<˘)≠↕1∾⊢) ' '="  string with  spaces   "  # All, then filtered, spaces
+
    (<˝≠↕1∾⊢) ' '="  string with  spaces   "  # All, then filtered, spaces
 ┌─                                                 
 ╵ 1 1 0 0 0 0 0 0 1 0 0 0 0 1 1 0 0 0 0 0 0 1 1 1  
   0 0 0 0 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0  
                                                   ┘
-    (⊢-˜¬×+`((<´<˘)≠↕1∾⊢))' '="  string with  spaces   "  # More processing
+    (⊢-˜¬×+`(<˝≠↕1∾⊢))' '="  string with  spaces   "  # More processing
 ┌─                                                         
 ╵  1  1 0 0 0 0 0 0  1 0 0 0 0  1  1 0 0 0 0 0 0  1  1  1  
   ¯1 ¯1 0 0 0 0 0 0 ¯1 1 1 1 1 ¯1 ¯1 2 2 2 2 2 2 ¯1 ¯1 ¯1  
                                                           ┘
-    ' '((⊢-˜¬×+`((<´<˘)≠↕1∾⊢))=⊔⊢)"  string with  spaces   "  # Final result
+    ' '((⊢-˜¬×+`(<˝≠↕1∾⊢))=⊔⊢)"  string with  spaces   "  # Final result
 ⟨ "string" "with" "spaces" ⟩
 
diff --git a/docs/doc/transpose.html b/docs/doc/transpose.html index 3b5af23b..93e5da73 100644 --- a/docs/doc/transpose.html +++ b/docs/doc/transpose.html @@ -3,7 +3,7 @@

Transpose

As in APL, Transpose () is a tool for rearranging the axes of an array. BQN's version is tweaked to align better with the leading axis model and make common operations easier.

Monadic Transpose

-

Transposing a matrix exchanges its axes, mirroring it across the diagonal. APL extends the function to any rank by reversing all axes, but this generalization isn't very natural and is almost never used. The main reason for it is to maintain the equivalence a MP b ←→ a MP b, where MP (+´<˘)×1 is the generalized matrix product. But even here APL's Transpose is suspect. It does much more work than it needs to, as we'll see.

+

Transposing a matrix exchanges its axes, mirroring it across the diagonal. APL extends the function to any rank by reversing all axes, but this generalization isn't very natural and is almost never used. The main reason for it is to maintain the equivalence a MP b ←→ a MP b, where MP +˝×1 is the generalized matrix product. But even here APL's Transpose is suspect. It does much more work than it needs to, as we'll see.

BQN's transpose takes the first axis of its argument and moves it to the end.

     a23456  23456
  2 3 4 5 6 
diff --git a/docs/doc/windows.html b/docs/doc/windows.html
index c20d6591..113d5ffd 100644
--- a/docs/doc/windows.html
+++ b/docs/doc/windows.html
@@ -81,11 +81,11 @@
 

A common task is to pair elements, with an initial or final element so the total length stays the same. This can also be done with a pairwise reduction, but another good way (and more performant without special support in the interpreter) is to add the element and then use windows matching the original length. Here both methods are used to invert +`, which requires we take pairwise differences starting at initial value 0.

    -˜´˘20 +` 3211
 ⟨ 3 2 1 1 ⟩
-    ((-˜´<˘)≠↕0∾⊢) +` 3211
+    (-˜˝≠↕0∾⊢) +` 3211
 ⟨ 3 2 1 1 ⟩
 

This method extends to any number of initial elements. We can modify the running sum above to keep the length constant by starting with two zeros.

-
    ((+´<˘)≠↕(20)) 2,6,0,1,4,3
+
    (+˝≠↕(20)) 2,6,0,1,4,3
 ⟨ 2 8 8 7 5 8 ⟩
 
diff --git a/docs/index.html b/docs/index.html index 57e708ba..711e419e 100644 --- a/docs/index.html +++ b/docs/index.html @@ -434,6 +434,12 @@
+ + + + + + diff --git a/docs/problems.html b/docs/problems.html index 252cdb1c..595ed18d 100644 --- a/docs/problems.html +++ b/docs/problems.html @@ -20,14 +20,6 @@

There are a lot of standard functions and I don't want to use separate primitives or a menu-style primitive like APL Circle for them. You can define all the functions eventually if you use complex exponential and take real and imaginary parts and inverses, but this doesn't sound well-suited for implementation. And there should be a math library that gives you the standard functions with normal names, but how will it be implemented?

Right-to-left multi-line functions go upwards

If you include multiple multi-line functions in what would otherwise be a one-liner, the flow in each function goes top to bottom but the functions are executed bottom to top. I think the fix here is to just say give your functions names and don't do this.

-

Array reductions are annoying

-

There are really three kinds of reduction a BQN programmer might want to use.

- -

It seems that the first is the most common, but the others aren't really rare. The current list reduction also encourages patterns like +´˘2mat, which don't work on higher-rank arrays and mix the result (possibly unwanted).

Subtraction, division, and span are backwards

The left argument feels much more like the primary one in these cases (indeed, this matches the typical left-to-right ordering of binary operators in mathematics). Not really fixable; too much precedent.

Can't access array ordering directly

@@ -104,6 +96,14 @@

I went with "Index of" and "Less Than or Equal to" but the last word blends into surrounding text. Should they be fully capitalized or hyphenated?

Solved problems

Problems that existed in mainstream APL or a transitional BQN that have in my opinion been put to rest (while in some cases introducing new problems). Listed in reverse chronological order by time solved, by my recollection.

+

Array reductions are annoying

+

There are really three kinds of reduction a BQN programmer might want to use.

+ +

BQN bounced between these some at first; eventually I decided it really needed two, with 𝔽˝ equivalent to 𝔽´<˘. The last requires two symbols, but they can always be used together as a unit, so I think this is no longer annoying.

"Modifier" and "composition" terminology

1-modifiers and 2-modifiers used to be called "modifiers" and "compositions", respectively, and sometimes "operators" collectively. The new names are much better, although they do leave a disconnect between the names for modifiers, and those for their inputs—"operands".

Can't return from inner functions

diff --git a/docs/spec/token.html b/docs/spec/token.html index c12fc3e4..3fcfbe6d 100644 --- a/docs/spec/token.html +++ b/docs/spec/token.html @@ -22,7 +22,7 @@ - + diff --git a/dzref b/dzref index 4ce64b25..c4c56596 100755 --- a/dzref +++ b/dzref @@ -24,7 +24,12 @@ _depthOp_←{ } 𝕨 n _d 𝕩 } +_insert←{ + ! 1≤=𝕩 + 𝕨 𝔽´ <˘𝕩 +} ⚇ ← _depthOp_ +˝ ← _insert #⌜ @@ -82,7 +87,7 @@ Join←{ IndexOf←(1<⌈○=)◶⊐‿{ c←1-˜=𝕨 ! 0≤c - 𝕨 (0<≠𝕨)◶⟨0⎉c∘⊢,((+´<˘)∧`)≢⎉c⎉c‿∞⟩ 𝕩 + 𝕨 (0<≠𝕨)◶⟨0⎉c∘⊢,(+˝∧`)≢⎉c⎉c‿∞⟩ 𝕩 } UniqueMask←{ ! 1≤=𝕩 @@ -132,8 +137,8 @@ _bins←{ c←1-˜=𝕨 ! 0≤c LE←𝔽⎉c≤0˜ - ! (0<≠)◶⟨1,∧´·LE´˘2↕<˘⟩𝕨 - 𝕨 (0<≠𝕨)◶⟨0⎉c∘⊢,(+´<˘)LE⎉¯1‿∞⟩ 𝕩 + ! (0<≠)◶⟨1,∧´·LE˝˘2↕⊢⟩𝕨 + 𝕨 (0<≠𝕨)◶⟨0⎉c∘⊢,+˝LE⎉¯1‿∞⟩ 𝕩 } OccurrenceCount ← ⊐˜(⊢-⊏)⍋∘⍋ @@ -148,7 +153,7 @@ X←Raw←{≤4} { chrs←⟨ "!=∾↕⌽⍉⍋⍒⊐⊒∊⍷" - "" + "˝" "⚇" ⟩ nc ← ≠¨chrs diff --git a/examples/fifty.bqn b/examples/fifty.bqn index 593f9e12..ad80a4b2 100644 --- a/examples/fifty.bqn +++ b/examples/fifty.bqn @@ -64,14 +64,14 @@ NewtonsMethod ← (2 ÷˜ ⊢ + ÷)´¨∘(1↓↑) ⥊ ! 1e¯5 > | (7 NewtonsMethod 2) - 2‿1.5‿1.41667‿1.41422‿1.41421‿1.41421‿1.41421 # 11 -InnerProduct ← (+´<˘)∘(ר)⎉1‿2 +InnerProduct ← +˝∘(ר)⎉1‿2 ! (>⟨2‿3⋄4‿1⟩) ≡ (>⟨1‿0⋄¯1‿1⟩) InnerProduct >⟨2‿3⋄6‿4⟩ # 12 CayleysTheorem ← {R←∾⊐⊢ ⋄ (R𝕩) ≡ R ⊏˜⌜˜ <˘R𝕩} ! { t ← 2‿2⊸⥊¨ (⌽2|⌊∘÷⟜2⍟(↕4))¨ 9‿6‿7‿11‿13‿14 - g ← (≠´<˘)∘(∧¨)⎉1‿2⌜˜t + g ← ≠˝∘(∧¨)⎉1‿2⌜˜t CayleysTheorem g } @@ -81,7 +81,7 @@ IntervalIndex ← 1-˜≠∘⊣(⊣↓⊢⍋⊸⊏+`∘>)⍋∘∾ # Or ⍋, of ! 0‿1‿0‿¯1‿4‿4 ≡ "Fi Jay John Morten Roger" IntervalIndex○Words "JD Jd Geoff Anna Scott Zeus" # 15 -CentralLimit ← { 41 ↑ /⁼ (5×↕40) ⍋ +´<˘ •Rand 𝕩⥊21 } +CentralLimit ← { 41 ↑ /⁼ (5×↕40) ⍋ +˝ •Rand 𝕩⥊21 } # 5‿8 ⥊ CentralLimit 10 1e3 # 17 diff --git a/md.bqn b/md.bqn index b55ad4f7..1fd0861a 100644 --- a/md.bqn +++ b/md.bqn @@ -262,7 +262,7 @@ Markdown ← {filename𝕊𝕩: codeMask ← ≠` I2M ⥊ codeBounds ← 1‿2⊸⊏˘ ctInds 𝕩 ↩ ' '¨⌾((codeMask∧𝕩=lf)⊸/) 𝕩 # If span has both a leading and a trailing space, they are removed. - remSpace ← I2M ⥊ ((1<-˜´˘)∧·∧´˘' '=⊏⟜𝕩)⊸/ -⟜0‿1˘ codeBounds + remSpace ← I2M ⥊ ((1<-˜˝˘)∧·∧˝˘' '=⊏⟜𝕩)⊸/ -⟜0‿1˘ codeBounds codeMask ∧↩ ¬ remSpace ⟨code,codePos⟩ ← codeMask extensions◶(2⥊<⟨⟩)‿GetMultiHighlights 𝕩 include ← ¬ remSpace ∨ ≠` I2M ⥊ ctInds @@ -404,7 +404,7 @@ GetHighlights ← { 0 , " "∾•UCS 9‿10 "Value" , ¯1⊏˘5‿2⥊"𝕨𝕩𝕗𝕘𝕤" "Function" , "+-×÷⋆√⌊⌈|¬∧∨<>≠=≤≥≡≢⊣⊢⥊∾≍↑↓↕⌽⍉/⍋⍒⊏⊑⊐⊒∊⍷⊔!"∾¯1⊏˘5‿2⥊"𝕎𝕏𝔽𝔾𝕊" - "Modifier" , "˜˘¨⌜⁼´`" + "Modifier" , "˜˘¨⌜⁼´˝`" "Modifier2" , "∘○⊸⟜⌾⊘◶⎉⚇⍟" "Number" , ∾idChars "Gets" , "←↩→" @@ -463,7 +463,7 @@ Fmt ← { (𝕨/" ") (∾⎉1∾⎉1⊣) 𝕩 } Pad ← PadH⟜PadV - Enframe ← {(1≠𝕨)∨(1≠≠𝕩)∨⊑2∊+`-´<˘"⟨⟩"=⌜⊏𝕩}◶{ + Enframe ← {(1≠𝕨)∨(1≠≠𝕩)∨⊑2∊+`-˝"⟨⟩"=⌜⊏𝕩}◶{ ≍"⟨"∾(¯1↓1↓⊏𝕩)∾"⟩" }‿{ l ← ¯1 ⊑ ≢𝕩 @@ -480,8 +480,8 @@ Fmt ← { }) PaddingJoin ← {1𝕊𝕩; s ← ≢¨ 𝕩 - w ← ⌈´⥊<⎉1 1⊑¨s - h ← ⌈´⎉1 ⊑¨s + w ← ⌈˝⍟(=-1˜)1⊑¨s + h ← ⌈˝⎉1 ⊑¨s ∾⎉2 ≍⍟(0⌈2-=) (h ∾⌜ 𝕨×w¬(-𝕨×≠w)↑1) ↑¨ 𝕩 } FmtMixed ← { diff --git a/problems.md b/problems.md index d9a68c88..c63af039 100644 --- a/problems.md +++ b/problems.md @@ -32,14 +32,6 @@ There are a lot of standard functions and I don't want to use separate primitive ### Right-to-left multi-line functions go upwards If you include multiple multi-line functions in what would otherwise be a one-liner, the flow in each function goes top to bottom but the functions are executed bottom to top. I think the fix here is to just say give your functions names and don't do this. -### Array reductions are annoying -There are really three kinds of reduction a BQN programmer might want to use. -- `𝔽´` Apply the function between elements of a list (Lisp). -- `𝔽´<˘` Apply it between major cells of an array (SHARP). -- `𝔽¨´<˘` Apply it between elements of an array, enclosing results to get a new array (NARS). - -It seems that the first is the most common, but the others aren't really rare. The current list reduction also encourages patterns like `+´˘2↕mat`, which don't work on higher-rank arrays and mix the result (possibly unwanted). - ### Subtraction, division, and span are backwards The left argument feels much more like the primary one in these cases (indeed, this matches the typical left-to-right ordering of binary operators in mathematics). Not really fixable; too much precedent. @@ -136,6 +128,14 @@ I went with "Index of" and "Less Than or Equal to" but the last word blends into Problems that existed in mainstream APL or a transitional BQN that have in my opinion been put to rest (while in some cases introducing new problems). Listed in reverse chronological order by time solved, by my recollection. +### Array reductions are annoying +There are really three kinds of reduction a BQN programmer might want to use. +- `𝔽´` Apply the function between elements of a list (Lisp). +- `𝔽˝` Apply it between major cells of an array (SHARP). +- `𝔽¨˝` Apply it between elements of an array, enclosing results to get a new array (NARS). + +BQN bounced between these some at first; eventually I decided it really needed two, with `𝔽˝` equivalent to `𝔽´<˘`. The last requires two symbols, but they can always be used together as a unit, so I think this is no longer annoying. + ### "Modifier" and "composition" terminology 1-modifiers and 2-modifiers used to be called "modifiers" and "compositions", respectively, and sometimes "operators" collectively. The new names are much better, although they do leave a disconnect between the names for modifiers, and those for their inputs—"operands". diff --git a/spec/reference.bqn b/spec/reference.bqn index 5d5424d8..1d0a5cca 100644 --- a/spec/reference.bqn +++ b/spec/reference.bqn @@ -182,6 +182,7 @@ Depth←IsArray◶0‿{1+0⌈´Depth¨⥊𝕩} ⚇ ← _depthOp_ ⍟ ← _iterate_ ˘ ← ⎉¯1 +˝ ← _insert ` ← _scan DropV← {⊑⟜𝕩¨𝕨+↕𝕨-˜≠𝕩} @@ -211,6 +212,10 @@ _rankOp_←{ } > ((⊑k)Enc𝕨) 𝔽¨ ((1-˜≠)⊸⊑k)Enc𝕩 } +_insert←{ + ! 1≤=𝕩 + 𝕨 𝔽´ <˘𝕩 +} _scan←{ ! IsArray 𝕩 ! 1≤=𝕩 @@ -354,7 +359,7 @@ Group←{ IndexOf←{ c←1-˜=𝕨 ! 0≤c - 𝕨 (0<≠𝕨)◶⟨0⎉c∘⊢,((+´<˘)∧`)≢⎉c⎉c‿∞⟩ 𝕩 + 𝕨 (0<≠𝕨)◶⟨0⎉c∘⊢,(+´˝∧`)≢⎉c⎉c‿∞⟩ 𝕩 } UniqueMask←{ ! 1≤=𝕩 @@ -403,8 +408,8 @@ _bins←{ c←1-˜=𝕨 ! 0≤c LE←𝔽⎉c≤0˜ - ! (0<≠)◶⟨1,∧´·LE´˘2↕<˘⟩𝕨 - 𝕨 (0<≠𝕨)◶⟨0⎉c∘⊢,(+´<˘)LE⎉¯1‿∞⟩ 𝕩 + ! (0<≠)◶⟨1,∧´·LE˝˘2↕⊢⟩𝕨 + 𝕨 (0<≠𝕨)◶⟨0⎉c∘⊢,+´˝LE⎉¯1‿∞⟩ 𝕩 } OccurrenceCount ← ⊐˜(⊢-⊏)⍋∘⍋ diff --git a/spec/token.md b/spec/token.md index 0cf05d0d..603abfa7 100644 --- a/spec/token.md +++ b/spec/token.md @@ -19,7 +19,7 @@ Otherwise, a single character forms a token. Only the specified set of character | Class | Characters |-----------------------|------------ | Primitive Function | `+-×÷⋆√⌊⌈\|¬∧∨<>≠=≤≥≡≢⊣⊢⥊∾≍↑↓↕⌽⍉/⍋⍒⊏⊑⊐⊒∊⍷⊔` -| Primitive 1-Modifier | `` ˜˘¨⌜⁼´` `` +| Primitive 1-Modifier | `` ˜˘¨⌜⁼´˝` `` | Primitive 1-Modifier | `∘○⊸⟜⌾⊘◶⎉⚇⍟` | Special name | `𝕨𝕩𝕗𝕘𝕤𝕎𝕏𝔽𝔾𝕊` | Punctuation | `←↩→(){}⟨⟩‿⋄,` and newline -- cgit v1.2.3
Operators
Syntax Monadic Dyadic
´
˝
or `
¨ ¨
˜
f.g (f´<˘)g1
f.g f˝g1
.f f
Ag Ag
fB fB
˝Insert
` Scan
Primitive 1-Modifier˜˘¨⌜⁼´`˜˘¨⌜⁼´˝`
Primitive 1-Modifier