chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Chicken-users] Windows deployment - Numbers egg


From: Robert Herman
Subject: [Chicken-users] Windows deployment - Numbers egg
Date: Sun, 4 Oct 2015 09:50:35 +0800

I have been learning Chicken by incrementally building a program that returns a number of digits of Pi based on an already-existing algorithm that implements the Chudnovsky method. I have a command line version working, thanks to all of the help here, that writes the file as well as displays the output in the command line.
If I just: csc Pi-Ch.scm I get a 77kB exe that runs fine on my machine. In order to share it with my son, I need to statically compile it with all of its dependencies, like so:

csc -deploy -static Pi-Ch.scm

I returns an error:

Error: (require) cannot load extension: numbers
        Call history:
        Pi-Ch.scm:16: ##sys#require             <--

I found the numbers.so file, but Windows needs a dll file. I plan on downloading the numbers egg source, and seeing if there's any reason I could not compile the numbers.so file to numbers.dll. Any leads or tips?

Next step will be to create an IUP GUI for the program to complete the exercise.

Thanks!

Rob

PS: Here's the code to date:

;;; Program to use the chudnovsky formula to compute pi.
;;; Written by Bakul Shah.
;;; Changed by Bradley Lucier to use standard arithmetic operations
;;; available in Gambit Scheme and to replace (floor (/ ...)) by
;;; (quotient ...)

;; Don't try running this benchmark with Gauche, it'll consume all
;; your computer's memory!

;;;; I removed the conditional statements to make it run across different
;;;; scheme implementations.
;;;; I added the use numbers and extras at the top, and the last 8 lines
;;;; to prompt user and to display the results and write to a file.
;;;; TODO: Deploy to Windows 32-bit, and create an IUP-based GUI for it.
;;;; RPH - 4/10/2015

(use numbers extras)

(define integer-sqrt exact-integer-sqrt)

(define ch-A 13591409)
(define ch-B 545140134)
(define ch-C 640320)
(define ch-C^3 (expt 640320 3))
(define ch-D 12)

(define (ch-split a b)
  (if (= 1 (- b a))
      (let ((g (* (- (* 6 b) 5) (- (* 2 b) 1) (- (* 6 b) 1))))
        (list g
              (quotient (* ch-C^3 (expt b 3)) 24)
              (* (expt -1 b) g (+ (* b ch-B) ch-A))))
      (let* ((mid (quotient (+ a b) 2))
             (gpq1 (ch-split a mid))    ;<<<<====
             (gpq2 (ch-split mid b))    ;<<<<====
             (g1 (car gpq1)) (p1 (cadr gpq1)) (q1 (caddr gpq1))
             (g2 (car gpq2)) (p2 (cadr gpq2)) (q2 (caddr gpq2)))
        (list (* g1 g2)
              (* p1 p2)
              (+ (* q1 p2) (* q2 g1))))))

(define (pich digits)
  (let* ((num-terms (inexact->exact (floor (+ 2 (/ digits 14.181647462)))))
         (sqrt-C (integer-sqrt (* ch-C (expt 100 digits)))))
    (let* ((gpq (ch-split 0 num-terms))
           (gs (car gpq)) (p (cadr gpq)) (q (caddr gpq)))
      (quotient (* p ch-C sqrt-C) (* ch-D (+ q (* p ch-A)))))))

(print "How many digits of Pi to compute?")
(define digits (read))

(print "Here you go:")
(print (pich digits))
(define file-name "pidigits.txt")
(with-output-to-file file-name
  (lambda ()
    (format #t "~A~%" (pich digits))))

reply via email to

[Prev in Thread] Current Thread [Next in Thread]