From 585c4b71a19021150a87df6d4d0811f4770bfbea Mon Sep 17 00:00:00 2001 From: Panadestein Date: Thu, 21 Nov 2024 11:27:37 +0100 Subject: [PATCH] refact: minor improvements si. --- src/bqn/si.bqn | 7 ++++--- src/si.org | 9 +++++---- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/bqn/si.bqn b/src/bqn/si.bqn index d63e2d3..7e74abe 100644 --- a/src/bqn/si.bqn +++ b/src/bqn/si.bqn @@ -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; 𝕊𝕩: { @@ -38,7 +38,7 @@ _sch ← { "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 𝕩 } @@ -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))" diff --git a/src/si.org b/src/si.org index d91270c..a279035 100644 --- a/src/si.org +++ b/src/si.org @@ -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 @@ -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; 𝕊𝕩: { @@ -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 @@ -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))" @@ -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!