Skip to content

Commit

Permalink
refact: minor improvements si.
Browse files Browse the repository at this point in the history
  • Loading branch information
Panadestein committed Nov 21, 2024
1 parent d9d6a35 commit 585c4b7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
7 changes: 4 additions & 3 deletions src/bqn/si.bqn
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ env ← @ C ⟨
|, ´, {𝕎𝕩}´, {𝕩}, , 1, <´
´_bool, ´, =´_bool, , , (0=•Type)_bool
{𝕎¨𝕩}´, ´, ´, 0_bool¬, @=_bool, (1=•Type)_bool
•Show, 0.5+⊢, 2=_bool{•Type⊑∾𝕩}, @, π
{𝕩}, 0.5+⊢, 2=_bool{•Type⊑∾𝕩}, @, π
˜ •math •ns.Get¨ "sin""cos""tan""asin""acos""atan"

_sch ← {
T(⊢/˜·´¨' ')·(-1·+`·¬»·+˝"( )"=)(⊢+22×@=10-˜)
T" "¨/·(-1·+`·¬»·+˝"( )"=)(⊢+22×@=10-˜)
R ← {
𝕊⟨⟩: "Empty program"!0;
𝕊𝕩: {
Expand All @@ -38,7 +38,7 @@ _sch ← {
"lambda"≡⊑𝕩 ? ·‿parbod𝕩𝕨{bod E˜ 𝕗 C par𝕩};
f𝕨𝕊⊑𝕩F 𝕨𝕊¨1𝕩
}
P(⊢+˝("( )"-""",‿⟩")×""",‿⟩"=)•Repr·1=(0<≠¨)/
psrs"( )"""",‿⟩"P ← (⊢+˝(ps-rs)×rs=)•Repr·1=(0<≠¨)/
P 𝕗E⊑RT 𝕩
}

Expand All @@ -52,6 +52,7 @@ R5RS ← {@+𝕩.Read¨ ↕1⊸+•_while_(0≠𝕩.Read)0}Ch

(Scheme⋈R5RS)¨
"(+ 10 122)"
"(max 5 6 7 1)"
"(* 4 2)"
"(begin (define r 10) (+ (/ 4 2) (* r r)))"
"(number? (quote b))"
Expand Down
9 changes: 5 additions & 4 deletions src/si.org
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ of the target subset, expressed as BQN functions:
|, ∾´, {𝕎𝕩}´, {∾𝕩}, ⊑∘∾, 1⊸↓∘∾, <⊸∾´
≡´_bool, ⋆´, =´_bool, ≠∘∾, ⊢, (0=•Type∘⊑)_bool
{𝕎∘⋈¨𝕩}´, ⌈´, ⌊´, 0⊸≠_bool¬, @⊸=_bool, (1=•Type∘⊑)_bool
•Show, ⌊0.5+⊢, 2⊸=_bool{•Type⊑∾𝕩}, @, π
{𝕩}, ⌊0.5+⊢, 2⊸=_bool{•Type⊑∾𝕩}, @, π
⟩ ∾˜ •math •ns.Get¨ "sin"‿"cos"‿"tan"‿"asin"‿"acos"‿"atan"
#+end_src

Expand All @@ -62,7 +62,7 @@ subsets of the language by changing the input global environment:

#+begin_src bqn :tangle ./bqn/si.bqn
_sch ← {
T ← (⊢/˜·∨´¨' '⊸≠)·(-⟜1·+`·¬⊸∧⟜»⊸∨·+˝"( )"=⌜⊢)⊸⊔(⊢+22×@=10-˜⊢)
T ← " "⊸≢¨⊸/·(-⟜1·+`·¬⊸∧⟜»⊸∨·+˝"( )"=⌜⊢)⊸⊔(⊢+22×@=10-˜⊢)
R ← {
𝕊⟨⟩: "Empty program"!0;
𝕊𝕩: {
Expand All @@ -80,7 +80,7 @@ subsets of the language by changing the input global environment:
"lambda"≡⊑𝕩 ? ·‿par‿bod ← 𝕩 ⋄ 𝕨{bod E˜ 𝕗 C par‿𝕩};
f ← 𝕨𝕊⊑𝕩 ⋄ F 𝕨⊸𝕊¨1↓𝕩
}
P(⊢+˝("( )"-"⟨"",‿⟩")×"⟨"",‿⟩"=⌜⊢)∘•Repr·1⊸=∘≠◶⊢‿⊑(0<≠¨)⊸/⎊⊢
ps‿rs ← "( )""⟨"",‿⟩" ⋄ P ← (⊢+˝(ps-rs)×rs=⌜⊢)∘•Repr·1⊸=∘≠◶⊢‿⊑(0<≠¨)⊸/⎊⊢
P 𝕗⊸E⊑R∘T 𝕩
}
#+end_src
Expand Down Expand Up @@ -132,6 +132,7 @@ people much prefer dealing with machinery to dealing with bureaucracies[fn:5]:
#+begin_src bqn :tangle ./bqn/si.bqn :exports both
(Scheme⋈R5RS)¨ ⟨
"(+ 10 122)"
"(max 5 6 7 1)"
"(* 4 2)"
"(begin (define r 10) (+ (/ 4 2) (* r r)))"
"(number? (quote b))"
Expand All @@ -148,7 +149,7 @@ people much prefer dealing with machinery to dealing with bureaucracies[fn:5]:
#+end_src

#+RESULTS:
: ⟨ ⟨ "132" "132" ⟩ ⟨ "8" "8" ⟩ ⟨ "102" "102" ⟩ ⟨ " #f " "#f" ⟩ ⟨ " #t " "#t" ⟩ ⟨ "42" "42" ⟩ ⟨ "1" "1" ⟩ ⟨ " #t " "#t" ⟩ ⟨ "2" "2" ⟩ ⟨ "1 1 2 3 5 8 13 21 34 55" "(1 1 2 3 5 8 13 21 34 55)" ⟩ ⟩
: ⟨ ⟨ "132" "132" ⟩ ⟨ "7" "7" ⟩ ⟨ "8" "8" ⟩ ⟨ "102" "102" ⟩ ⟨ " #f " "#f" ⟩ ⟨ " #t " "#t" ⟩ ⟨ "42" "42" ⟩ ⟨ "1" "1" ⟩ ⟨ " #t " "#t" ⟩ ⟨ "2" "2" ⟩ ⟨ "1 1 2 3 5 8 13 21 34 55" "(1 1 2 3 5 8 13 21 34 55)" ⟩ ⟩


If you manage to find any sneaky corner cases that break the interpreter in the given subset, let me know!
Expand Down

0 comments on commit 585c4b7

Please sign in to comment.