aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarshall Lochbaum <mwlochbaum@gmail.com>2020-06-07 16:05:26 -0400
committerMarshall Lochbaum <mwlochbaum@gmail.com>2020-06-07 16:05:26 -0400
commit77dbb1bff776de7614d047910137bcf833872a2a (patch)
tree63108888416e15172b65c40dcb95a1b48ba85aa0
parent4b6eac4476f3b44595dec71f0ad0dea2fa7abee6 (diff)
Support reciprocal using a function call
-rwxr-xr-xc.bqn21
1 files changed, 11 insertions, 10 deletions
diff --git a/c.bqn b/c.bqn
index 88f75739..f7beb8fa 100755
--- a/c.bqn
+++ b/c.bqn
@@ -1,8 +1,8 @@
#!/usr/bin/env bqn
Parse←{
- x←𝕩
+ ⟨⟩Parse𝕩;args←𝕨⋄x←𝕩
a←x='←'⋄at←1⌽a⋄vars←at/x⋄x(/˜)↩¬a⋄a(/˜)↩¬at
- l←≠x⋄o←x='('⋄c←x=')'⋄sep←x='⋄'⋄v←a-˜x∊•d∾vars⋄f←¬o∨c∨v∨sep
+ l←≠x⋄o←x='('⋄c←x=')'⋄sep←x='⋄'⋄v←a-˜x∊•d∾args∾vars⋄f←¬o∨c∨v∨sep
na←(2×sep)+f×1+l↑0∾c∨v
e←/c⋄d←+`o-c
ed←e⊏d⋄b←(⍋⍋ed)⊏(⍋⊏⟜d)⊸⊏/o
@@ -11,12 +11,12 @@ Parse←{
fe⌊↩(l-1)-l↑(⌈`↕∘≠⊸×)⌾⌽1∾˜sep
ia←+`l↑0∾f-l↑/⁼∧f/fe
sel←¬∘⊏⟜(o∨c)⊸/⍋(fe⌈↕l)-ia
- ⟨sel⊸⊏¨x‿na,vars⟩
+ ⟨sel⊸⊏¨x‿na,args∾vars,vars⟩
}
-d64←127-3
+f64←127-3
GenFn←{
- ⟨x‿na,vars⟩←𝕩
+ ⟨x‿na,vars,locs⟩←𝕩
D←16⊥(•d∾"ABCDEF")⊸⊐
fns←{
n←•d⊐<𝕩
@@ -26,11 +26,11 @@ GenFn←{
(D"44")∾2⊥˘⌽8‿8(⊣⥊×´⊸↑)∾⟨⥊0,(11⥊2)⊤1023+l,(2⥊˜0⌈l)⊤n⟩
}‿{
v←vars⊐<𝕩⋄v<≠vars:(D"22")∾v
- (⥊¨(D"99")+((↕4)∾6))⊑˜"|-⌈⌊√"⊐<𝕩
+ ((<(D"10")∾1)∾˜⥊¨(D"99")+((↕4)∾6))⊑˜"|-⌈⌊√÷"⊐<𝕩
}‿{
(⥊¨(D"1A")∾(D"A0")+↕6)⊑˜"⋄+-×÷⌊⌈"⊐<𝕩
}
- ((≠∾∾)⟨vars≠⊸∾d64⟩)∾(D"0B")∾˜∾na⊑⟜fns⊸{𝕎𝕩}¨x
+ ((≠∾∾)⟨locs≠⊸∾f64⟩)∾(D"0B")∾˜∾na⊑⟜fns⊸{𝕎𝕩}¨x
}
Gen←{
@@ -43,14 +43,15 @@ Gen←{
∾⟨
0∾(•UCS"asm")∾4↑1
1 S V (96∾⟜∾C¨)¨t
- 3 S V ⥊¨↕≠n
+ 3 S V ⥊¨↕≠b
7 S V I⊸(⊣∾0∾⊢)¨⟜(↕∘≠)n
10 S V C¨ b
}
Compile←{
- body←GenFn Parse 𝕩
- (1↓∾)(","∾⥊∘⍕)¨ Gen ⟨⟨0‿1⟩/¨¨d64 ⋄ ⥊<"fn" ⋄ ⥊<body⟩
+ body←GenFn∘Parse 𝕩
+ rcp←"x" GenFn∘Parse "1÷x"
+ (1↓∾)(","∾⥊∘⍕)¨ Gen ⟨⟨0‿1,1‿1⟩/¨¨f64 ⋄ ⥊<"fn" ⋄ ⟨body,rcp⟩⟩
}
•←Compile "b←3⋄d←(b×b)-4×2×1⋄((-b)+√d)÷2×2"