-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathbqn-mode.el
2872 lines (2423 loc) Β· 76.4 KB
/
bqn-mode.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
;;; bqn-mode.el --- Emacs mode for BQN -*- lexical-binding: t -*-
;; Emacs bqn-mode is derived from gnu-apl-mode,
;; which is copyright 2013-2015 Elias MΓ₯rtenson <[email protected]>.
;; Changes are copyright 2021 Marshall Lochbaum <[email protected]>.
;; Author: Marshall Lochbaum <[email protected]>
;; Version: 0.1.0
;; Package-Requires: ((emacs "26.1") (compat "30.0.0.0") (eros "0.1.0"))
;; URL: https://github.com/museoa/bqn-mode
;; SPDX-License-Identifier: GPL-3.0-or-later
;;; Commentary:
;; Emacs major mode for BQN programming language.
;;; Code:
(require 'comint)
(require 'quail)
(require 'pulse)
(defvar bqn-keymap-mode-reference
"\
ββββββ¬βββββ¬βββββ¬βββββ¬βββββ¬βββββ¬βββββ¬βββββ¬βββββ¬βββββ¬βββββ¬βββββ¬βββββ¬ββββββββββ
β~ Β¬ β! β β@ β β# β β$ βΆ β% β β^ β β& β* β( β¨ β) β© β_ β β+ β βBackspaceβ
β` Λ β1 Λ β2 Β¨ β3 βΌ β4 β β5 Β΄ β6 Λ β7 β8 β β9 Β― β0 β’ β- Γ· β= Γ β β
ββββββ΄βββ¬ββ΄βββ¬ββ΄βββ¬ββ΄βββ¬ββ΄βββ¬ββ΄βββ¬ββ΄βββ¬ββ΄βββ¬ββ΄βββ¬ββ΄βββ¬ββ΄βββ¬ββ΄βββ¬ββ΄βββ¬βββββββ€
βTab βQ βW π βE β· βR π£ βT β βY βU βI β βO β βP β{ β£ β} β’ β| β
β βq β½ βw π¨ βe β βr β βt β§ βy βu β βi β βo β βp Ο β[ β β] β\\ β
βββββββββ΄β¬ββββ΄β¬ββββ΄β¬ββββ΄β¬ββββ΄β¬ββββ΄β¬ββββ΄β¬ββββ΄β¬ββββ΄β¬ββββ΄β¬ββββ΄β¬ββββ΄β¬ββββ΄βββββββ€
βCaps βA βS π βD βF π½ βG πΎ βH Β« βJ βK βΎ βL Β» β: Β· β\" Λ βEnter β
βLock βa β βs π€ βd β βf π βg π βh βΈ βj β βk β βl β β; β β' β© β β
ββββββββββ΄βββ¬ββ΄βββ¬ββ΄βββ¬ββ΄βββ¬ββ΄βββ¬ββ΄βββ¬ββ΄βββ¬ββ΄βββ¬ββ΄βββ¬ββ΄βββ¬ββ΄βββ¬ββ΄βββββββββββ€
βShift βZ β βX π βC βV β βB β βN βM β’ β< β€ β> β₯ β? β βShift β
β βz β₯ βx π© βc β βv β¨ βb β βn βm β‘ β, βΎ β. β β/ β β β
βββββββββββββ΄βββββ΄βββββ΄βββββ΄βββββ΄βββββ΄βββββ΄βββββ΄βββββ΄βββββ΄βββββ΄βββββββββββββ
Space: βΏ"
"Keyboard map for BQN.")
(defvar bqn-keymap-mode-*buffer-name* "*BQN keymap*"
"Name of the BQN keymap buffer.")
(defun bqn-keymap-mode-show-keyboard ()
"Display the keyboard help."
(interactive)
(let ((keyboard-help (get-buffer bqn-keymap-mode-*buffer-name*)))
(unless (and keyboard-help (get-buffer-window keyboard-help))
;; The buffer is not displayed.
(let* ((buffer (get-buffer-create bqn-keymap-mode-*buffer-name*))
(window (split-window nil)))
(with-current-buffer buffer
(insert bqn-keymap-mode-reference)
(goto-char (point-min))
(bqn-keymap-mode))
(set-window-buffer window buffer)
(fit-window-to-buffer window)))))
(define-derived-mode bqn-keymap-mode special-mode "BQN-Keymap"
"Major mode for displaying the keymap help."
(buffer-face-set 'bqn-default)
(read-only-mode 1)
(setq truncate-lines t))
(defvar bqn-glyph-mode-reference
"βββββ¬βββββββββββββββββ¬βββββββββββββββ¬ββββ¬βββββββββββββββββββ¬βββββββββββββββββ
β @ β Monadic β Dyadic β @ β Monadic β Dyadic β
βββββΌβββββββββββββββββΌβββββββββββββββΌββββΌβββββββββββββββββββΌβββββββββββββββββ€
β + β Conjugate β Add β β₯ β Deshape β Reshape β
β β β Negate β Subtract β βΎ β Join β Join to β
β Γ β Sign β Multiply β β β Solo β Couple β
β Γ· β Reciprocal β Divide β β β Enlist β Pair β
β β β Exponential β Power β β β Prefixes β Take β
β β β Square Root β Root β β β Suffixes β Drop β
β β β Floor β Minimum β β β Range β Windows β
β β β Ceiling β Maximum β Β» β Nudge β Shift Before β
β β§ β Sort Up β And β Β« β Nudge Back β Shift After β
β β¨ β Sort Down β Or β β½ β Reverse β Rotate β
β Β¬ β Not β Span β β β Transpose β Reorder Axes β
β β β Absolute Value β Modulus β / β Indices β Replicate β
β β€ β β No More Than β β β Grade Up β Bins Up β
β < β Enclose β Less Than β β β Grade Down β Bins Down β
β > β Merge β Greater Than β β β First Cell β Select β
β β₯ β β No Less Than β β β First β Pick β
β = β Rank β Equals β β β Classify β Index of β
β β β Length β Not Equals β β β Occurrence Count β Progressive β β
β β‘ β Depth β Match β β β Mark Firsts β Member of β
β β’ β Shape β Not Match β β· β Deduplicate β Find β
β β£ β Identity β Left β β β Group Indices β Group β
β β’ β Identity β Right β ! β Assert β Assert Message β
βββββ΄βββββββββββββββββ΄βββββββββββββββ΄ββββ΄βββββββββββββββββββ΄βββββββββββββββββ"
"Glyph Lookup Table for BQN.")
(defvar bqn-glyph-mode-*buffer-name* "*BQN Glyphs*")
(defun bqn-glyph-mode-show-glyphs ()
"Display a table of BQN glyphs."
(interactive)
(let ((glyph-buffer (get-buffer bqn-glyph-mode-*buffer-name*)))
(unless (and glyph-buffer (get-buffer-window glyph-buffer))
;; The buffer is not displayed.
(let* ((buffer (get-buffer-create bqn-glyph-mode-*buffer-name*))
(window (split-window nil)))
(with-current-buffer buffer
(insert bqn-glyph-mode-reference)
(goto-char (point-min))
(bqn-glyph-mode))
(set-window-buffer window buffer)
(fit-window-to-buffer window)))))
(define-derived-mode bqn-glyph-mode special-mode "BQN-Glyphs"
"Major mode for displaying the BQN Glyph help."
(buffer-face-set 'bqn-default)
(read-only-mode 1)
(setq truncate-lines t))
;;; BQN Symbols documentation
;; Arrays and hashes are not very Lispy, however they will be employed here
;; because we want the lowest latency possible for an end-user-facing structure.
;; For all intents and purposes, this table should be regarded as read-only;
;; indeed, it is "cached" at byte-compile time via eval-when-compile.
(defconst bqn--symbols
(eval-when-compile
(let ((table '(
;; top row
(?\` . [ nil
"π½` π©: Scan | π¨ π½` π©: Scan With Initial"
"\
π½` π©: Scan
- Scan over π© with π½ from left to right, producing intermediate values.
π¨ π½` π©: Scan With initial
- Monadic scan, but use π¨ as initial left argument."
"\
+` 1βΏ2βΏ3
β¨ 1 3 6 β©
β¨1, 1+2, (1+2)+3β©
β¨ 1 3 6 β©
-` 1βΏ2βΏ3
β¨ 1 Β―1 Β―4 β©
β¨1, 1-2, (1-2)-3β©
β¨ 1 Β―1 Β―4 β©
5 +` 1βΏ2βΏ3
β¨ 6 8 11 β©
β¨5+1, (5+1)+2, ((5+1)+2)+3β©
β¨ 6 8 11 β©
5 -` 1βΏ2βΏ3
β¨ 4 2 Β―1 β©
β¨5-1, (5-1)-2, ((5-1)-2)-3β©
β¨ 4 2 Β―1 β©"])
(?Λ . [ ?\`
"π½Λ π©: Self | π¨ π½Λ π©: Swap"
"\
π½Λ π©: Self
- Supplies π© as a left argument to π½ (π© π½ π©).
π¨ π½Λ π©: Swap
- Swaps the arguments of π½ (π© π½ π¨)."
"\
1 + 1
2
+Λ 1
2
1 - 2
Β―1
1 -Λ 2
1"])
(?Β¬ . [ ?~
"Β¬ π©: Logical Not | π¨ Β¬ π©: Span"
"\
Β¬ π©: Logical Not
- Logical Not of π©.
- Pervasive.
π¨ Β¬ π©: Span
- Count of numbers in the inclusive range from π© to π¨.
- Pervasive."
"\
Β¬ 0
1
Β¬ 1βΏ0
β¨ 0 1 β©
3 Β¬ 1
3
3βΏ4 Β¬ 0βΏ2
β¨ 4 3 β©"])
(?! . [ nil
"! π©: Assert | π¨ ! π©: Assert With Message"
"\
! π©: Assert
- Throw an error if π© is not 1.
π¨ ! π©: Assert With Message
- Throw an error with message π¨ if π© is not 1."
"\
! 1
1
! 2
Error: Assertion error
! \"hello\"
Error: hello
\"hi\" ! 1
1
\"two\" ! 2
Error: two
\"hello error\" ! \"hello\"
Error: hello error"])
(?Λ . [ ?1
"π½Λ π©, π¨ π½Λ π©: Cells"
"\
π½Λ π©, π¨ π½Λ π©: Cells
- Apply π½ to/between the major cells of the arguments. (π½βΒ―1)"
"\
a β 3βΏ3 β₯ β9
<Λ a
β¨ β¨ 0 1 2 β© β¨ 3 4 5 β© β¨ 6 7 8 β© β©
a βΛ a
ββ
β 0 1 2
0 1 2
3 4 5
3 4 5
6 7 8
6 7 8
β"])
(?β . [ ?!
"π½βπ π©, π¨ π½βπ π©: Rank"
"\
π½βπ π©, π¨ π½βπ π©: Rank
- Apply π½ to cells at ranks given in π. Non-negative numbers indicate the rank
of the cell and negative ones indicate the difference from full rank.
- The ranks applied are given by the following:
- β c Rank-c cells of π© (monadic) or both arguments (dyadic)
- β bβΏc Rank-b cells of π¨ and rank-c cells of π© (dyadic)
- β aβΏbβΏc Rank-a cells of π© (monadic), b-cells of π¨ and c-cells of π© (dyadic)"
"\
a β 3βΏ2βΏ4β₯\"ABCDEFGHIJKLMNOPQRSTUVWXYZ\"
β½β2 a
ββ
β\"EFGH
ABCD
Β·MNOP
IJKL
Β·UVWX
QRST\"
β"])
(?@ . [ nil
"Null Character"
"\
@: Null Character
- Code point 0 in ASCII.
- Add to a code point number to ger that character."
"\
@+50
'2'
@
@
@+64
'@'"])
(?Β¨ . [ ?2
"π½Β¨ π©, π¨ π½Β¨ π©: Each"
"\
π½Β¨ π©, π¨ π½Β¨ π©: Each
- Apply π½ to/between the elements of the arguments. (π½βΒ―1)"
"\
<Β¨ 1βΏ2βΏ3
ββ
Β· βΒ· βΒ· βΒ·
Β· 1 Β· 2 Β· 3
β β β
β
4βΏ5βΏ6 βΎΒ¨ 1βΏ2βΏ3
β¨ β¨ 4 1 β© β¨ 5 2 β© β¨ 6 3 β© β©"])
(?β . [ ?@
"π½βπ π©, π¨ π½βπ π©: Depth"
"\
π½βπ π©, π¨ π½βπ π©: Depth
- Apply π½ to the cells of the arguments at depth given in π.
- Negative numbers count down from the top level and non-negative ones from the
bottom up."
"\
1βΈββ1 β¨β¨1,2,3β©, β¨4,5,6β©β©
β¨ β¨ 2 3 β© β¨ 5 6 β© β©
1 ββ1 β¨β¨1,2,3β©, β¨4,5,6β©β©
β¨ β¨ 2 3 β© β¨ 5 6 β© β©
(+Β΄β)β0 β¨2,4βΏ7,3β© # Implements pervasion
β¨ 1 β¨ 6 21 β© 3 β©"])
(?\# . [ nil
"#: Comment"
"\
#: Comment
- Create a comment that extends to the end of the line.
- Anything written in comments is ignored.
"
"\
1 + 2 # + 3 + 4
3
\"Hello world!\" # this is ignored!
\"Hello world!\""])
(?βΌ . [ ?3
"π½βΌ π©, π¨ π½βΌ π©: Undo"
"\
π½βΌ π©, π¨ π½βΌ π©: Undo"
"\
1 - 2
Β―1
1 -βΌ 2
Β―1
β 16
4
ββΌ 4
16
β 1
2.718281828459045
ββΌ 2.718281828459045
1"])
(?β . [ ?\#
"π½βπΎ π©, π¨ π½βπΎ π©: Repeat"
"\
π½βπΎ π©, π¨ π½βπΎ π©: Repeat
- Apply πΎ to π¨ and π©, then apply π½ to π© that many times.
- If π¨ is given, use it each time as a constant left argument.
- If πΎ returns an array, give π½βπ© for each of its elements."
"\
1 +ββ’ 4
8
1 +β1βΏ2βΏ3 4
β¨ 5 6 7 β©
3 βΎβ{β π©} β¨4,5,6β©
β¨ 3 3 3 4 5 6 β©"])
(?β . [ ?4
"π¨ π½β π©: Table"
"\
π¨ π½β π©: Table
- Apply π½ between every possible pair of the elements of the arguments."
"\
1βΏ2βΏ3βΏ4 +β 4βΏ5βΏ6βΏ7
ββ
β΅ 5 6 7 8
6 7 8 9
7 8 9 10
8 9 10 11
β
\"abc\" βΎβ \"xyz\"
ββ
β΅ \"ax\" \"ay\" \"az\"
\"bx\" \"by\" \"bz\"
\"cx\" \"cy\" \"cz\"
β
"])
(?βΆ . [ ?$
"π½βΆπ π©, π¨ π½βΆπ π©: Choose"
"\
π½βΆπ π©, π¨ π½βΆπ π©: Choose
- Apply π½ to the arguments and use the result to pick (β) a function from list
π.
- Apply the picked function to the arguments."
"\
F β β’βΆ+βΏ-βΏΓ·βΏΓ
F 0
0
F 1
Β―1
F 2
0.5"])
(?Β΄ . [ ?5
"π½Β΄ π©: Fold | π¨ π½Β΄ π©: Fold With Initial"
"\
π½Β΄ π©: Fold
- Fold over π© with π½ from right to left i.e. Insert π½ between the elements of π©.
- π© must be a simple list (1 = =π©).
π¨ π½Β΄ π©: Fold With Initial
- Monadic fold, but use π¨ as initial right argument."
"\
+Β΄ 1βΏ2βΏ3
6
1+2+3
6
-Β΄ 1βΏ2βΏ3
2
1-2-3
2
5 +Β΄ 1βΏ2βΏ3
11
1+2+3+5
11
5 -Β΄ 1βΏ2βΏ3
Β―3
1-2-3-5
Β―3"])
(?β . [ ?%
"π½βπΎ π©: Valences | π¨ π½βπΎ π©: Dyadic Valences"
"\
π½βπΎ π©: Valences
- Apply π½ to π©.
π¨ π½βπΎ π©: Dyadic Valences
- Apply πΎ to π¨ and π©."
"\
+β- 5
5
-β+ 5
Β―5
4 +β- 5
Β―1
4 -β+ 5
9"])
(?Λ . [ ?6
"π½Λ π©: Insert | π¨ π½Λ π©: Insert With Initial"
"\
π½Λ π©: Insert
- Fold over cells of π© with π½ from end to start, that is, insert π½ between the
major cells of π©.
π¨ π½Λ π©: Insert With Initial
- Monadic insert, but use π¨ as initial right argument."
"\
a β 3βΏ3 β₯ β9
+Λ a
β¨ 9 12 15 β©
0βΏ1βΏ2 + 3βΏ4βΏ5 + 6βΏ7βΏ8
β¨ 9 12 15 β©
b β 3βΏ3 β₯ β9
1βΏ1βΏ1 +Λ b
β¨ 10 13 16 β©
1 +Λ b
β¨ 10 13 16 β©
0βΏ1βΏ2 + 3βΏ4βΏ5 + 6βΏ7βΏ8 + 1βΏ1βΏ1
β¨ 10 13 16 β©"])
(?β . [ ?^
"π½βπΎ π©, π¨ π½βπΎ π©: Catch"
"\
π½βπΎ π©, π¨ π½βπΎ π©: Catch
- Apply π½ to the arguments.
- If an error happens when π½ is applied, cancel its execution, apply πΎ to the
arguments and return its result.
- Otherwise, return the result of π½.
"
"\
βΎβ{\"error occurred with argument: \"βΎβ’Fmt π©} 1
\"error occurred with argument: 1\"
βΎβ{\"error occurred with argument: \"βΎβ’Fmt π©} β¨β¨1,2β©, β¨3,4β©β©
β¨ 1 2 3 4 β©
"])
(?β . [ ?8
"β: Infinity"
"\
β: Infinity
- Mathematical constant Infinity, a numeric literal. Can be negative (Β―β)."
"\
β
β
Β―β
Β―β
1+β
β"])
(?\( . [ nil
"(: Begin Expression"
"\
(: Begin Expression
- Starts an expression, and only one expression.
- Must end with a corresponding ).
- ( supercedes any precedence order, so that an expression in () is evaluated
fully before it can be used in the outer context."
"\
1 + 2 - 3
0
(1 + 2) - 3
0"])
(?Β― . [ ?9
"Β―: Minus"
"\
Β―: Minus
- Prefix before numbers to indicate that they are negative.
- Note that this is not the same as -, since it is part of the number, rather
than a primitive that negates its value."
"\
-1βΏ2βΏ3
β¨ Β―1 Β―2 Β―3 β©
Β―1βΏ2βΏ3
β¨ Β―1 2 3 β©"])
(?β¨ . [ ?\(
"β¨: Begin list"
"\
β¨: Begin list
- Starts a list.
- Inner elements must be separated by , or β.
- Lists can be nested in other lists.
- Must end with a corresponding β©."
"\
β¨1, 2, 3β©
β¨ 1 2 3 β©
β¨+ β - β 56β©
β¨ + - 56 β©"])
(?\) . [ nil
"): End Expression)"
"\
): End Expression
- The closing symbol for (.
- See ( documentation for more details."
"\
1 + 2 - 3
0
(1 + 2) - 3
0"])
(?β’ . [ ?0
"β’: System"
"\
β’: System
- A prefix for system functions.
- β’listSys gives a list of defined system value names.
- β’ is ignored when determining the role of the system value."
"\
"])
(?β© . [ ?\)
"β©: End list)"
"\
β©: End list
- Ends a list started by a β¨.
- See β¨ documentation for more details."
"\
β¨1, 2, 3β©
β¨ 1 2 3 β©
β¨+ β - β 56β©
β¨ + - 56 β©"])
(?- . [ nil
"- π©: Negate | π¨ - π©: Subtract"
"\
- π©: Negate
- Additive Inverse of π©.
π¨ - π©: Subtract
- Subtract π© from π¨.
- π¨ and π© can be characters or numbers."
"\
- 1
Β―1
- Β―1
1
1 - 2
Β―1
1 - 2βΏ3βΏ4
β¨ Β―1 Β―2 Β―3 β©
'a' - 4
']'
'b' - 'a'
1"])
(?Γ· . [ ?-
"Γ· π©: Reciprocal | π¨ Γ· π©: Divide"
"\
Γ· π©: Reciprocal
- Gives 1 Γ· π©.
- Pervasive.
π¨ Γ· π©: Divide
- π¨ divided by π©.
- Pervasive."
"\
Γ· 5
0.2
5 Γ· 4
1.25
14 Γ· 7
2
"])
(?β . [ ?_
"β π©: Square root | π¨ β π©: Root"
"\
β π©: Square root
- Self-explaining.
- Pervasive.
π¨ β π©: Root
- π¨ th root of π©.
- Pervasive."
"\
β 2
1.4142135623730951
2 β 2
1.4142135623730951
1βΏ2βΏ3βΏ4 β 4
β¨ 4 2 1.5874010519681994 1.4142135623730951 β©"])
(?= . [ nil
"= π©: Rank | π¨ = π©: Equal To"
"\
= π©: Rank
- Returns the number of dimensions in π©.
π¨ = π©: Equal To
- Do argument atoms match?
- Pervasive."
"\
= 0
0
= 3β₯0
1
= 3βΏ3β₯0
2
3βΏ3βΏ3 β₯ β¨β¨0β©β©
ββ
β β¨ 0 β© β¨ 0 β© β¨ 0 β©
β¨ 0 β© β¨ 0 β© β¨ 0 β©
β¨ 0 β© β¨ 0 β© β¨ 0 β©
β¨ 0 β© β¨ 0 β© β¨ 0 β©
β¨ 0 β© β¨ 0 β© β¨ 0 β©
β¨ 0 β© β¨ 0 β© β¨ 0 β©
β¨ 0 β© β¨ 0 β© β¨ 0 β©
β¨ 0 β© β¨ 0 β© β¨ 0 β©
β¨ 0 β© β¨ 0 β© β¨ 0 β©
β
1 = 3
0
2βΏ3βΏ0 = 3βΏ1βΏ0
β¨ 0 0 1 β©
'a' = 'a'
1"])
(?+ . [ nil
"+ π©: Conjugate | π¨ + π©: Add"
"\
+ π©: Conjugate
- Complex conjugate of π©.
- BQN doesn't support complex numbers yet, so it has no effect.
π¨ + π©: Add
- π¨ added to π©.
- Either π¨ or π© can be a character, and if so, the other has to be an integer.
- Pervasive."
"\
+ 1
1
+ Β―1
Β―1
1 + 2
3
1 + 2βΏ3βΏ4
β¨ 3 4 5 β©
'a' + 4
'e'"])
(?Γ . [ ?=
"Γ π©: Sign | π¨ Γ π©: Multiply"
"\
Γ π©: Sign
- Sign of π©.
- Β―1 if π© < 0
- 0 if π© = 0
- 1 if π© > 0
- Pervasive.
π¨ Γ π©: Multiply
- π¨ multiplied by π©.
- Pervasive."
"\
Γ Β―5βΏ0βΏ5βΏ1
β¨ Β―1 0 1 1 β©
1 Γ 2
2
2 Γ 2βΏ3βΏ4
β¨ 4 6 8 β©
"])
(?β . [ ?+
"β π©: Exponential | π¨ β π©: Power"
"\
β π©: Exponential
- e (Euler's constant) to the power of π©.
- Pervasive.
π¨ β π©: Power
- π¨ to the power of π©.
- Pervasive."
"\
β 0βΏ1βΏ2βΏ3
β¨ 1 2.718281828459045 7.38905609893065 20.085536923187668 β©
2 β 5
32
8βΏ5βΏ9 β 2
β¨ 64 25 81 β©
2βΏ3 β 3βΏΒ―4
β¨ 8 0.012345679012345678 β©"])
;; first row
(?β½ . [ ?q
"β½ π©: Reverse | π¨ β½ π©: Rotate"
"\
β½ π©: Reverse
- Reverse π© along the first axis.
π¨ β½ π©: Rotate
- Move the first π¨ elements of π© to its end. Negative π¨ reverses the direction
of rotation."
"\
β½ 1βΏ2βΏ3
β¨ 3 2 1 β©
a β 3βΏ3 β₯ β9
β½ a
ββ
β΅ 6 7 8
3 4 5
0 1 2
β
2 β½ 1βΏ2βΏ3
β¨ 3 1 2 β©
b β 3βΏ3 β₯ β9
2 β½ b
ββ
β΅ 6 7 8
0 1 2
3 4 5
β"])
(?π¨ . [ ?w
"π¨: Left Argument"
"\
π¨: Left Argument
- A variable assigned to the left argument of a block.
- π can be used to access the left argument as a function."
"\
5 {π¨} 1
5
-βΏΓ· {ππ©}Β¨ 4
β¨ Β―4 0.25 β©"])
(?π . [ ?W
"π: Left Argument"
"\
π¨: Left Argument
- A variable assigned to the left argument of a block.
- π can be used to access the left argument as a function."
"\
5 {π¨} 1
5
-βΏΓ· {ππ©}Β¨ 4
β¨ Β―4 0.25 β©"])
(?β . [ ?e
"β π©: Mark Firsts | π¨ β π©: Member Of"
"\
β π©: Mark Firsts
- Mark the first occurrence of each major cell in π© with a 1, and all other
occurrences with a 0.
π¨ β π©: Member Of
- Is each cell in π¨ a major cell of π©?"
"\
β 4βΏ5βΏ6βΏ6βΏ4βΏ7βΏ5
β¨ 1 1 1 0 0 1 0 β©
a β 3βΏ3 β₯ β9
β a
β¨ 1 1 1 β©
β¨1β© β β9
β¨ 1 β©
b β 3βΏ3 β₯ β9
β¨0βΏ1βΏ2β© β b
βΒ·
Β· 0
β
β¨1βΏ3 β₯ 0βΏ1βΏ2β© β b
βΒ·
Β· 0
β"])
(?β· . [ ?E
"β· π©: Deduplicate | π¨ β· π©: Find"
"\
β· π©: Deduplicate
- Unique major cells of π©.
π¨ β· π©: Find
- Mark the top left location of the occurrences of π¨ in π© with a 1, and other
locations with 0.
- Result is the same shape as (β’π¨)βx."
"\
β· 4βΏ5βΏ6βΏ6βΏ4βΏ7βΏ5
β¨ 4 5 6 7 β©
a β 3βΏ3 β₯ β6
β· a
ββ
β΅ 0 1 2
3 4 5
β
\"string\" β· \"substring\"
β¨ 0 0 0 1 β©
\"loooooong\" β· \"short\"
β¨β©
b β 7 (4|βΛ)βββ 9
c β (0βΏ3βΏ0β0βΏ1βΏ0)
c β· b
ββ
β΅ 0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 1 0 0 0 1
0 0 0 0 0 0 0
0 0 1 0 0 0 1
β"])
(?β . [ ?r
"β π©: Prefixes | π¨ β π©: Take"
"\
β π©: Prefixes
- Prefixes of array π© along its first axis.
π¨ β π©: Take
- For each integer in π¨, take that many elements from each dimension of π©.
- Negative numbers take from the end.
- If any of the elements in π¨ are greater than the length of their respective
dimension, the dimension is extended with a fill value."
"\
β 1βΏ2βΏ3βΏ4
β¨ β¨β© β¨ 1 β© β¨ 1 2 β© β¨ 1 2 3 β© β¨ 1 2 3 4 β© β©
a β 3βΏ3 β₯ β9
β a
ββ
Β· β0βΏ3 ββ ββ ββ
β΅ 0 1 2 β΅ 0 1 2 β΅ 0 1 2
β 3 4 5 3 4 5
β 6 7 8
β
β
3 β 1βΏ3βΏ5βΏ67
β¨ 1 3 5 β©
b β 4βΏ4 β₯ β16
3βΏ3 β b
ββ
β΅ 0 1 2
4 5 6
8 9 10
β
5βΏ5 β b
ββ
β΅ 0 1 2 3 0
4 5 6 7 0
8 9 10 11 0
12 13 14 15 0
0 0 0 0 0
β
3βΏΒ―3 β b
ββ
β΅ 1 2 3
5 6 7
9 10 11
β"])
(?π£ . [ ?R
"π£: Current Modifier"
"\
π£: Current Modifier
- A variable assigned to the current modifier block.
- Add underscores to the beginning and/or end (_π£, _π£_) to use it in a modifier
role."
"\
+{π£β£π©} 4
(1-modifier block)"])
(?β§ . [ ?t
"β§ π©: Sort Up | π¨ β§ π©: Logical And"
"\
β§ π©: Sort Up
- Sort array π© in ascending order.
π¨ β§ π©: Logical And
- Logical And of π¨ and π©.
- Pervasive."
"\
β§ 3βΏ1βΏ4βΏ1βΏ5
β¨ 1 1 3 4 5 β©
1 β§ 1
1
1βΏ0 β§ 1βΏ1
β¨ 1 0 β©
"])
(?β . [ ?T
"β π©: Grade Up | π¨ β π©: Bins Up"
"\
β π©: Grade Up
- Indices of π© that would sort its major cells in ascending order.
π¨ β π©: Bins Up
- Binary search for each cell of π© in π¨, returning the number of major cells in
π¨ less than or equal to that cell.
- π¨ must be sorted in ascending order."
"\
a β 3βΏ2βΏ1
β a
β¨ 2 1 0 β©