mirror of
https://github.com/vinc/moros.git
synced 2024-06-19 15:37:08 +00:00
* 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
17 lines
330 B
Common Lisp
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))))))
|