BASIC Developer & Support Resources > Scripting Languages

Elk Scheme Extension Module.

(1/2) > >>

John:
In the process to trying to get a Fibonacci Scheme script running under TinyScheme it produced the wrong answer. The TinyScheme extension module was just a minimal API connection to Scheme. Basically a Scheme EVAL function.

I ran into Elk Scheme which has an extensive C API and BIGINT support. I would like to create an extension module for ScriptBasic with Elk. My hope is Mike will have a casual interest and mentor this project along.

Elk Project Site   Git Repository

Here is the 1 million digit fabonacci in Elk. It took an hour and 15 minutes in ScriptBasic native.

--- Code: Scheme ---; Fibonacci using fast doubling formulas, good for millions of digits!(define (fibo n)    (cond        ((= n 0) 0)        ((= n 1) 1)        (else             (let*                (                    (k (quotient n 2))                    (a (fibo k))                    (b (fibo (- k 1)))                )                 (if (even? n)                    (* a (+ (* 2 b) a))                    (let*                        (                            (2a (* 2 a))                            (c (* (+ 2a b) (- 2a b)))                        )                         (if (= (modulo n 4) 1)                            (+ c 2)                            (- c 2)                        )                    )                )            )        )    ))(Display (fibo 4784969))

jrs@jrs-laptop:~/sb/examples/test\$ time elk -l elkfibo.scm > elkfibo.out

real   11m1.066s
user   11m0.855s
sys   0m0.016s
jrs@jrs-laptop:~/sb/examples/test\$ ls -l elkfibo.out
-rw-r--r-- 1 jrs jrs 1000000 May 27 18:40 elkfibo.out
jrs@jrs-laptop:~/sb/examples/test\$ tail -c64 elkfibo.out
6330930391815964864885353407167474856539211500699706378405156269
jrs@jrs-laptop:~/sb/examples/test\$

Mike Lobanovsky:

--- Quote from: John on May 27, 2019, 06:33:01 pm ---... TinyScheme ... produced the wrong answer.
--- End quote ---

No wonder. TinyScheme has no BIGINT support, and it can only perform calc on, and print, numeric quantities it supports natively, of which double precision is the largest.

And thanks but no, I am not interested. Elk is a full scale ...NIX-oriented project with only minimal support for Windows. It can probably take one's lifetime to develop and maintain a Windows fork of it as a hobby, which isn't exactly my idea of bumming around in the declension of my years. ;)

John:
Actually TinyScheme wasn't at fault, it was the users Scheme code. Thanks for your feed back on Elk.

Mike Lobanovsky:
What does a corrected version of Scheme script look like, please?

John:
Here is a Fibonacci Scheme example that works great in TinyScheme.

Heater@RPi  posted the funky Scheme code that made me think TinyScheme was broken.

I think ScriptBasic and Scheme would make a very powerful language.

RPI Post