-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
prime.apln
99 lines (88 loc) · 3.22 KB
/
prime.apln
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
:Namespace prime
⎕IO←1 ⋄ ⎕ML←1
Err←{⍞←⍵,⎕UCS 13}
∇ {text}←UpdateReadme path;head;tail;file
file←path,'/README.md'
text←⊃⎕NGET file 1
head←(3↑¨text)⍳⊂'| -'
tail←'⎕[\w←]+'⎕R'`&`'{'|[',('_'⎕R'\\_'⊢⍵),'](',⍵,'.apl',(' fo'⊃⍨⊃##.⎕NC ⍵),')',⊃'⍝ (.) (.*)'⎕S'|`\1`|\2|'⊃##.⎕NR ⍵}¨##.⎕NL-3 4
text←tail,⍨head↑text
file 1 ⎕NPUT⍨⊂text
∇
∇ {ns}←Repl target;input;n;v
2022⌶⍣('W'=⊃⊃# ⎕WG'APLVersion')⊤⍨⍬
:If ×≢target
ns←⍎(⍕target)##.⎕NS ##.⎕NL-3 4
:Else
ns←##.(⎕NS ⎕NL-3 4)
:EndIf
⍞←'Dyalog APL/',⊃⊃v←# ⎕WG'APLVersion'
⍞←(⊃v)∩'-',⎕D
⍞←' Version ',¯2↓2⊃v
⍞←n←⎕UCS 13
⍞←'Serial No : 123456',n
⍞←'Prime Edition',n
⍞←'Sun' 'Mon' 'Tue' 'Wed' 'Thu' 'Fri' 'Sat'⊃⍨1+7|2 ⎕NQ #'DateToIDN'⎕TS
⍞←' ','-- ::.'@5 8 11 14 17 20∊⍕¨0 100 100 100 100 100 1000+⎕TS
⍞←n
:While '→'≢⊃⌽' '~⍨input←⍞⊣⍞←6⍴''
:Trap 0
:Select ⊃input~' '
:Case ']'
⎕←⎕SE.UCMD input
:Case ')'
⎕←ns Execute'⎕'@(input⍳')')⊢input
:Else
⎕←ns Execute input
:EndSelect
:Else
⍞←((⊢↓⍨'⍎'=⊃)(⊃⎕DM),(×≢⎕DMX.Message)/': ',⎕DMX.Message),⎕UCS 13
⍞←(' ',10↓⊃1↓⎕DM),⎕UCS 13
⍞←(' ',10↓⊃2↓⎕DM),⎕UCS 13
:EndTrap
:EndWhile
ns.⎕EX ##.⎕NL-3 4
∇
∇ {ref}←{mode}FIX srcFile;files;file;src;code;glyph;glyphs;names;from;to;loaded;pattern
src←⍬
loaded←5177⌶⍬
pattern←'*.apl?',⍨⊃⎕NPARTS loaded⊃⍨4,⍨⎕THIS⍳⍨⊃¨loaded
files←(⍒⊃¨⊂)⊃⎕NINFO⍠1⊢pattern
glyphs←names←0⍴⊂''
:For file :In files
code←⊃⎕NGET file 1
glyph←'⍝ (\W\S*)'⎕S'\1'⊃code
:If ≢glyph
glyphs,←glyph
names,←2⌷⎕NPARTS file
:If '}'=⊃⌽' '~⍨∊code
src,←code
:Else
src,←'∇'∘,¨@1⊢code,⊂,'∇'
:EndIf
:EndIf
:EndFor
code←⊃⎕NGET(srcFile↓⍨7×'file://'≡7↑srcFile)1
:If 900⌶⍬
mode←⊢
:EndIf
ref←mode ⎕FIX(1↑code),src,glyphs To names⊢1↓code
∇
To←{
mask←×⊃∘⍴¨⍺⍺
fromIgnore←'''[^'']*''' '⍝.*' '`(.)'
fromGlyphs←'\W' '\w\b'⎕R'\\&' '&\\b'⊢mask/⍺⍺
from←fromIgnore,fromGlyphs
toIgnore←'&' '&' '\1'
toGlyphs←'^|$'⎕R' '⊢mask/⍵⍵
to←toIgnore,toGlyphs
from ⎕R to⊢⍵
}
Execute←{
names←##.⎕NL-3 4
glyphs←⊃¨'⍝ (\W\S*)'⎕S'\1'¨⊃∘##.⎕NR¨names
⍺←##.⎕NS names
85::⍬⊤⍬
1 ⍺.(85⌶)glyphs To names⊢⍵
}
:EndNamespace