1
5
mirror of https://github.com/vinc/moros.git synced 2024-06-19 15:37:08 +00:00
moros/dsk/tmp/lisp/pi.lsp
Vincent Ollivier 1bafa2271c
Add apply to Lisp (#410)
* Replace mapcar by apply

* Add map and reduce to core lib

* Add pi.lsp example

* Fix tests

* Refactor pi-digits

* Move builtin join to core lib as string-join

* Rename decode-* and encode-* to *-decode and *-encode

* Update doc
2022-09-15 20:50:23 +02:00

17 lines
330 B
Common Lisp

(load "/lib/lisp/core.lsp")
(defn pi-nth (n)
(* (^ 16 (- n)) (-
(/ 4 (+ 1 (* 8 n)))
(/ 2 (+ 4 (* 8 n)))
(/ 1 (+ 5 (* 8 n)))
(/ 1 (+ 6 (* 8 n))))))
(defn pi-digits (n)
(apply + (map pi-nth (range 0 n))))
(println
(cond
((null? args) "Usage: pi <precision>")
(true (pi-digits (parse (car args))))))