-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6380722
commit 2183187
Showing
5 changed files
with
81 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
sbcl: | ||
PI_ARG=$(PI_ARG) make -f Makefile.sbcl run | ||
|
||
clean: | ||
rm -f pi.fas pi.lib pi.o |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
CLISP=sbcl | ||
CLOPTS=--control-stack-size 256 --script | ||
|
||
run: | ||
@$(CLISP) $(CLOPTS) pi.cl $(PI_ARG) | ||
|
||
clean: | ||
rm -f pi.fas pi.lib pi.o |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
**Note:** for stack size reasons this version only currently works on SBCL. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
; PI Common LISP example. | ||
|
||
; Abstract getting command line arguments. | ||
; In sbcl the interpreter is an extra argument. | ||
|
||
; For CLISP: clisp pi.cl <n> | ||
; For SBCL: sbcl --script pi.cl <n> | ||
; For GCL: gcl -f pi.cl <n> | ||
; For ECL: ecl -shell pi.cl <n> | ||
|
||
(defun getargs () | ||
(or | ||
#+CLISP *args* | ||
#+SBCL (cdr *posix-argv*) | ||
#+GCL (cdr si::*command-args*) | ||
#+ECL (cdr(cdr(cdr si::*command-args*))) | ||
nil)) | ||
|
||
(defun range (b n j) | ||
(if (>= b n) | ||
'() | ||
(cons b (range (+ b j) n j)) | ||
) | ||
) | ||
|
||
|
||
(defun pc (c) (/ (apply #'+ (map 'list #'(lambda (x) (/ 4 (+ 1 (* x x))))((lambda (n) (range (/ 0.5 n) 1 (/ 1 n))) c))) c)) | ||
|
||
(defvar n 5000000) | ||
|
||
(if (> (list-length(getargs)) 0) | ||
(setq n (parse-integer (car (getargs)))) | ||
) | ||
|
||
(format t "Calculating PI using~%") | ||
(format t " ~a slices~%" n) | ||
(format t " 1 process~%") | ||
|
||
; get-internal-real-time gets time from some arbitrary, implementation | ||
; dependent starting point in some fraction of a second. | ||
(defvar start (get-internal-real-time)) | ||
|
||
(defvar p (pc n)) | ||
|
||
; get-internal-real-time is in some platform specific unit which we can find in | ||
; internal-time-units-per-second | ||
(defvar stop (get-internal-real-time)) | ||
|
||
(defvar runt (/ (- stop start) internal-time-units-per-second)) | ||
|
||
(format t "Obtained value of PI: ~a~%" p) | ||
|
||
; We have to print the time with ~f to force a float output. | ||
(format t "Time taken: ~f seconds~%" runt) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Detect which if any Common LISP implementation we have: | ||
which sbcl > /dev/null 2>&1 | ||
sbclsuccess=$? | ||
|
||
if [ "$sbclsuccess" == "0" ]; then | ||
PI_ARG=$1 make -f Makefile.sbcl | ||
else | ||
echo "No Common LISP implementation found." | ||
exit 1 | ||
fi |