Skip to content

Commit

Permalink
Hopefully better BQN
Browse files Browse the repository at this point in the history
  • Loading branch information
Panadestein committed Mar 7, 2024
1 parent a52ead4 commit 548ae52
Show file tree
Hide file tree
Showing 69 changed files with 409 additions and 120 deletions.
189 changes: 69 additions & 120 deletions content/index.org
Original file line number Diff line number Diff line change
Expand Up @@ -922,118 +922,6 @@ for the IRPF90 derived mode, which are also included here.
(use-package yasnippet
:straight t
:config
;; BQN snippets
(yas-define-snippets
'bqn-mode '(("sign" "×" "Function: Sign, Multiply")
("multiply" "×" "Function: Sign, Multiply")
("reciprocal" "÷" "Function: Reciprocal, Divide")
("divide" "÷" "Function: Reciprocal, Divide")
("exponential" "⋆" "Function: Exponential, Power")
("power" "⋆" "Function: Exponential, Power")
("square root" "√" "Function: Square Root, Root")
("root" "√" "Function: Square Root, Root")
("floor" "⌊" "Function: Floor, Minimum")
("minimum" "⌊" "Function: Floor, Minimum")
("ceiling" "⌈" "Function: Ceiling, Maximum")
("maximum" "⌈" "Function: Ceiling, Maximum")
("sort up" "∧" "Function: Sort Up, And")
("and" "∧" "Function: Sort Up, And")
("sort down" "∨" "Function: Sort Down, Or")
("or" "∨" "Function: Sort Down, Or")
("not" "¬" "Function: Not, Span")
("span" "¬" "Function: Not, Span")
("less than or equal to" "≤" "Function: Less Than or Equal to")
("greater than or equal to" "≥" "Function: Greater Than or Equal to")
("length" "≠" "Function: Length, Not Equals")
("not equals" "≠" "Function: Length, Not Equals")
("depth" "≡" "Function: Depth, Match")
("match" "≡" "Function: Depth, Match")
("shape" "≢" "Function: Shape, Not Match")
("not match" "≢" "Function: Shape, Not Match")
("identity" "⊣" "Function: Identity, Left")
("left" "⊣" "Function: Identity, Left")
("identity" "⊢" "Function: Identity, Right")
("right" "⊢" "Function: Identity, Right")
("deshape" "⥊" "Function: Deshape, Reshape")
("reshape" "⥊" "Function: Deshape, Reshape")
("enlist" "⋈" "Function: Enlist, Pair")
("pair" "⋈" "Function: Enlist, Pair")
("join" "∾" "Function: Join, Join to")
("join to" "∾" "Function: Join, Join to")
("solo" "≍" "Function: Solo, Couple")
("couple" "≍" "Function: Solo, Couple")
("prefixes" "↑" "Function: Prefixes, Take")
("take" "↑" "Function: Prefixes, Take")
("suffixes" "↓" "Function: Suffixes, Drop")
("drop" "↓" "Function: Suffixes, Drop")
("range" "↕" "Function: Range, Windows")
("windows" "↕" "Function: Range, Windows")
("shift before" "«" "Function: Shift Before")
("shift after" "»" "Function: Shift After")
("reverse" "⌽" "Function: Reverse, Rotate")
("rotate" "⌽" "Function: Reverse, Rotate")
("transpose" "⍉" "Function: Transpose, Reorder axes")
("reorder axes" "⍉" "Function: Transpose, Reorder axes")
("grade up" "⍋" "Function: Grade Up, Bins Up")
("bins up" "⍋" "Function: Grade Up, Bins Up")
("grade down" "⍒" "Function: Grade Down, Bins Down")
("bins down" "⍒" "Function: Grade Down, Bins Down")
("first cell" "⊏" "Function: First Cell, Select")
("select" "⊏" "Function: First Cell, Select")
("first" "⊑" "Function: First, Pick")
("pick" "⊑" "Function: First, Pick")
("classify" "⊐" "Function: Classify, Index of")
("index of" "⊐" "Function: Classify, Index of")
("occurrence count" "⊒" "Function: Occurrence Count, Progressive Index of")
("progressive index of" "⊒" "Function: Occurrence Count, Progressive Index of")
("mark first" "∊" "Function: Mark First, Member of")
("member of" "∊" "Function: Mark First, Member of")
("deduplicate" "⍷" "Function: Deduplicate, Find")
("find" "⍷" "Function: Deduplicate, Find")
("group indices" "⊔" "Function: Group Indices, Group")
("group" "⊔" "Function: Group Indices, Group")
("constant" "˙" "Modifier: Constant")
("self/swap" "˜" "Modifier: Self/Swap")
("atop" "∘" "Modifier2: Atop")
("over" "○" "Modifier2: Over")
("before/bind" "⊸" "Modifier2: Before/Bind")
("after/bind" "⟜" "Modifier2: After/Bind")
("under" "⌾" "Modifier2: Under")
("valences" "⊘" "Modifier2: Valences")
("choose" "◶" "Modifier2: Choose")
("rank" "⎉" "Modifier2: Rank")
("cells" "˘" "Modifier: Cells")
("depth" "⚇" "Modifier2: Depth")
("each" "¨" "Modifier: Each")
("table" "⌜" "Modifier: Table")
("repeat" "⍟" "Modifier2: Repeat")
("undo" "⁼" "Modifier: Undo")
("fold" "´" "Modifier: Fold")
("insert" "˝" "Modifier: Insert")
("define" "←" "Gets: Define")
("export" "⇐" "Gets: Export")
("change" "↩" "Gets: Change")
("return" "→" "Gets: Return")
("separator" "⋄" "Separator: Separator")
("begin list" "⟨" "Bracket: Begin list")
("end list" "⟩" "Bracket: End list")
("strand" "‿" "Ligature: Strand")
("nothing" "·" "Nothing: Nothing")
("system" "•" "Value: System")
("left argument" "𝕨" "Value: Left argument")
("left argument (as function)" "𝕎" "Function: Left argument (as function)")
("right argument" "𝕩" "Value: Right argument")
("right argument (as function)" "𝕏" "Function: Right argument (as function)")
("modifier left operand (as subject)" "𝕗" "Value: Modifier left operand (as subject)")
("modifier left operand" "𝔽" "Function: Modifier left operand")
("2-modifier right operand (as subject)" "𝕘" "Value: 2-modifier right operand (as subject)")
("2-modifier right operand" "𝔾" "Function: 2-modifier right operand")
("current function (as subject)" "𝕤" "Value: Current function (as subject)")
("current function" "𝕊" "Function: Current function")
("current modifier" "𝕣" "Modifier: Current modifier")
("minus" "¯" "Nothing: Minus")
("pi" "π" "Nothing: Pi")
("infinity" "∞" "Nothing: Infinity")))
;; Enable everywhere
(yas-global-mode 1))
#+end_src
Expand Down Expand Up @@ -1617,16 +1505,14 @@ For this, the =macrostep= package comes very handy.
*APL* stands for [[https://www.softwarepreservation.org/projects/apl/Books/APROGRAMMING%20LANGUAGE][A Programmin Language]], make your own conclusions. It is an absolute joy to program
in Iversonian array languages. Tacit and terse, less is more.

*** BQN
*** COMMENT BQN

An APL for your flying saucer:

#+begin_src emacs-lisp
(use-package bqn-mode
:straight t
:init
;; Get rid of *Quail Completions*
(defun quail-completion ())
;; Rudimentary org-babel support
(add-to-list 'org-babel-tangle-lang-exts '("bqn" . "bqn"))
(defun org-babel-expand-body:bqn (body params &optional processed-params)
Expand All @@ -1642,7 +1528,7 @@ An APL for your flying saucer:
vars "\n")
"\n" body "\n")))
(defun org-babel-execute:bqn (body params)
"Execute a block of Bqn code with org-babel."
"Execute a block of BQN code with org-babel."
(message "Executing BQN source code block")
(bqn-comint-evaluate-command body))
(defun org-babel-bqn-var-to-bqn (var)
Expand All @@ -1652,18 +1538,81 @@ An APL for your flying saucer:
"If there is not a current inferior-process-buffer in SESSION then create."
(unless (string= session "none")
(get-buffer-process (bqn-comint-buffer))))

;; Some utilities
(defun toggle-bqn-keymap ()
"Toggle the BQN keymap display."
(interactive)
(let ((buf (get-buffer "*BQN keymap*")))
(if (and buf (get-buffer-window buf))
(progn
(delete-window (get-buffer-window buf))
(kill-buffer buf))
(bqn-keymap-mode-show-keyboard))))
(defun toggle-bqn-glyphs ()
"Toggle the BQN glyphs display."
(interactive)
(let ((buf (get-buffer "*BQN Glyphs*")))
(if (and buf (get-buffer-window buf))
(progn
(delete-window (get-buffer-window buf))
(kill-buffer buf))
(bqn-glyph-mode-show-glyphs))))

;; Too much color in BQN is not good
(defun disable-rainbow-delimiters-bqn ()
(rainbow-delimiters-mode -1))

;; And the default fontlock needs work
(defface bqn-function
'((t (:foreground "#3aa548")))
"Face used for BQN functions."
:group 'bqn)
(defface bqn-one-modifier
'((t (:foreground "#93428b")))
"Face used for BQN 1-modifiers."
:group 'bqn)
(defface bqn-two-modifier
'((t (:foreground "#998819")))
"Face used for BQN 2-modifiers."
:group 'bqn)
(defface bqn-primitive-function
'((t (:foreground "#3aa548")))
"Face used for primitive BQN functions."
:group 'bqn)
(defface bqn-primitive-one-modifier
'((t (:foreground "#93428b")))
"Face used for primitive BQN 1-modifiers."
:group 'bqn)
(defface bqn-primitive-two-modifier
'((t (:foreground "#998819")))
"Face used for primitive BQN 2-modifiers."
:group 'bqn)
(defun my-bqn-mode-custom-strings ()
"Customize string face for BQN mode."
(set (make-local-variable 'font-lock-string-face)
'(:foreground "#ABB2BF")))

:bind (:map bqn-mode-map
("M-i" . bqn-help-symbol-info-at-point)
("C-c g" . bqn-glyph-mode-show-glyphs)
("C-c k" . bqn-keymap-mode-show-keyboard)
("C-c g" . toggle-bqn-glyphs)
("C-c k" . toggle-bqn-keymap)
("C-c C-e" . bqn-comint-eval-buffer)
("C-x C-e" . bqn-comint-eval-dwim))
:hook (bqn-mode . bqn-comint-buffer)
:hook ((bqn-mode . bqn-comint-buffer)
(bqn-mode . disable-rainbow-delimiters-bqn)
(bqn-mode . my-bqn-mode-custom-strings))
:config
;; Glyphs and keyboard layout
(require 'bqn-keymap-mode)
(require 'bqn-glyph-mode))
(require 'bqn-glyph-mode)
;; Get rid of *Quail Completions*
(defun quail-completion ()))
#+end_src

#+RESULTS:
: bqn-comint-eval-dwim

*** Uiua

Point free or die. Stack based, array oriented, general purpose programming language.
Expand Down
5 changes: 5 additions & 0 deletions snippets/bqn-mode/and.yasnippet
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# -*- mode: snippet -*-
# name: Function: Sort Up, And
# key: and
# --
5 changes: 5 additions & 0 deletions snippets/bqn-mode/bins_down.yasnippet
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# -*- mode: snippet -*-
# name: Function: Grade Down, Bins Down
# key: bins down
# --
5 changes: 5 additions & 0 deletions snippets/bqn-mode/bins_up.yasnippet
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# -*- mode: snippet -*-
# name: Function: Grade Up, Bins Up
# key: bins up
# --
5 changes: 5 additions & 0 deletions snippets/bqn-mode/ceiling.yasnippet
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# -*- mode: snippet -*-
# name: Function: Ceiling, Maximum
# key: ceiling
# --
5 changes: 5 additions & 0 deletions snippets/bqn-mode/classify.yasnippet
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# -*- mode: snippet -*-
# name: Function: Classify, Index of
# key: classify
# --
5 changes: 5 additions & 0 deletions snippets/bqn-mode/constant.yasnippet
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# -*- mode: snippet -*-
# name: Modifier: Constant
# key: constant
# --
˙
5 changes: 5 additions & 0 deletions snippets/bqn-mode/couple.yasnippet
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# -*- mode: snippet -*-
# name: Function: Solo, Couple
# key: couple
# --
5 changes: 5 additions & 0 deletions snippets/bqn-mode/deduplicate.yasnippet
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# -*- mode: snippet -*-
# name: Function: Deduplicate, Find
# key: deduplicate
# --
5 changes: 5 additions & 0 deletions snippets/bqn-mode/depth.yasnippet
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# -*- mode: snippet -*-
# name: Function: Depth, Match
# key: depth
# --
5 changes: 5 additions & 0 deletions snippets/bqn-mode/deshape.yasnippet
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# -*- mode: snippet -*-
# name: Function: Deshape, Reshape
# key: deshape
# --
5 changes: 5 additions & 0 deletions snippets/bqn-mode/divide.yasnippet
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# -*- mode: snippet -*-
# name: Function: Reciprocal, Divide
# key: divide
# --
÷
5 changes: 5 additions & 0 deletions snippets/bqn-mode/drop.yasnippet
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# -*- mode: snippet -*-
# name: Function: Suffixes, Drop
# key: drop
# --
5 changes: 5 additions & 0 deletions snippets/bqn-mode/enlist.yasnippet
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# -*- mode: snippet -*-
# name: Function: Enlist, Pair
# key: enlist
# --
5 changes: 5 additions & 0 deletions snippets/bqn-mode/exponential.yasnippet
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# -*- mode: snippet -*-
# name: Function: Exponential, Power
# key: exponential
# --
5 changes: 5 additions & 0 deletions snippets/bqn-mode/find.yasnippet
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# -*- mode: snippet -*-
# name: Function: Deduplicate, Find
# key: find
# --
5 changes: 5 additions & 0 deletions snippets/bqn-mode/first.yasnippet
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# -*- mode: snippet -*-
# name: Function: First, Pick
# key: first
# --
5 changes: 5 additions & 0 deletions snippets/bqn-mode/first_cell.yasnippet
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# -*- mode: snippet -*-
# name: Function: First Cell, Select
# key: first cell
# --
5 changes: 5 additions & 0 deletions snippets/bqn-mode/floor.yasnippet
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# -*- mode: snippet -*-
# name: Function: Floor, Minimum
# key: floor
# --
5 changes: 5 additions & 0 deletions snippets/bqn-mode/grade_down.yasnippet
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# -*- mode: snippet -*-
# name: Function: Grade Down, Bins Down
# key: grade down
# --
5 changes: 5 additions & 0 deletions snippets/bqn-mode/grade_up.yasnippet
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# -*- mode: snippet -*-
# name: Function: Grade Up, Bins Up
# key: grade up
# --
5 changes: 5 additions & 0 deletions snippets/bqn-mode/greater_than_or_equal_to.yasnippet
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# -*- mode: snippet -*-
# name: Function: Greater Than or Equal to
# key: greater than or equal to
# --
5 changes: 5 additions & 0 deletions snippets/bqn-mode/group.yasnippet
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# -*- mode: snippet -*-
# name: Function: Group Indices, Group
# key: group
# --
5 changes: 5 additions & 0 deletions snippets/bqn-mode/group_indices.yasnippet
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# -*- mode: snippet -*-
# name: Function: Group Indices, Group
# key: group indices
# --
5 changes: 5 additions & 0 deletions snippets/bqn-mode/identity.yasnippet
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# -*- mode: snippet -*-
# name: Function: Identity, Right
# key: identity
# --
Loading

0 comments on commit 548ae52

Please sign in to comment.