par: add proplogic

This commit is contained in:
Kyle Isom 2018-04-07 01:58:49 -07:00
parent ed28464c04
commit 05a88c1a29
2 changed files with 47 additions and 0 deletions

38
par/prime.scm Normal file
View File

@ -0,0 +1,38 @@
(define first car)
(define rest cdr)
(define (prime-numbers amount from)
(if (= amount 0)
'()
(if (prime? from)
(cons from (prime-numbers (- amount 1) (+ from 1)))
(prime-numbers amount (+ from 1)))))
(define (divisors n from)
(if (> from n)
'()
(if (= (remainder n from) 0)
(cons from (divisors n (+ from 1)))
(divisors n (+ from 1)))))
(define (prime? number)
(equal? (divisors number 1) (list 1 number)))
(define (square x) (* x x))
(define (squares list-of-numbers)
(if (eq? list-of-numbers '())
'()
(cons (square (first list-of-numbers)) (squares (rest list-of-numbers)))))
(define (map f list)
(if (eq? list '())
'()
(cons (f (first list)) (map f (rest list)))))
(define (sum numbers)
(if (eq? numbers '())
0
(+ (first numbers) (sum (rest numbers)))))
;; (sum (map square (prime-numbers 7 1)))

9
par/proplogic.scm Normal file
View File

@ -0,0 +1,9 @@
(let ((pamphlet (string-append (getenv "HOME") "/src/pamphlet/libraries")))
(add-to-load-path pamphlet))
(use-modules (ice-9 nice-9) (srfi srfi-1) (pamphlet))
(define (lookup key mapping)
(let* ((((name . value) . remaining) mapping))
(if (eq? name key)
value
(lookup key remaining))))