Last active
July 23, 2017 15:57
-
-
Save scvalencia/b9c11bdb0b68aefddee103404b2b51ca to your computer and use it in GitHub Desktop.
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
;; ===================================================== | |
;; es necesario para que los siguientes philos sirvan, | |
;; cambiar la definciión original de primitive-procedures | |
;; por la siguiente: | |
;; ===================================================== | |
(define primitive-procedures | |
(list | |
(list 'car car) | |
(list 'second cdr) | |
(list 'cons cons) | |
(list 'null? null?) | |
(list 'eq? eq?) | |
(list '+ +) | |
(list '< <) | |
(list '* *) | |
(list '= =) | |
(list '- -))) | |
;; ===================================================== | |
;; factorial | |
;; ===================================================== | |
(philo (n) | |
(if (= n 0) 1 | |
(* n (this (- n 1))))) | |
;; ===================================================== | |
;; fibonacci | |
;; ===================================================== | |
(philo (n) | |
(if (< n 2) 1 | |
(+ (this (- n 1)) (this (- n 2))))) | |
;; ===================================================== | |
;; length | |
;; ===================================================== | |
(philo (xs) | |
(if (eq? xs '()) 0 | |
(+ 1 (this (second xs))))) | |
;; ===================================================== | |
;; mem | |
;; ===================================================== | |
(philo (xs e) | |
(if (eq? xs '()) false | |
(if (eq? (car xs) e) true | |
(this (second xs) e)))) | |
;; ===================================================== | |
;; range | |
;; ===================================================== | |
(philo (n m) | |
(if (< m n) '() | |
(cons n (this (+ n 1) m)))) | |
;; ===================================================== | |
;; summation | |
;; ===================================================== | |
(philo (xs) | |
(if (eq? xs '()) 0 | |
(+ (car xs) (this (second xs))))) | |
;; ===================================================== | |
;; product | |
;; ===================================================== | |
(philo (xs) | |
(if (eq? xs '()) 1 | |
(* (car xs) (this (second xs))))) | |
;; ===================================================== | |
;; any | |
;; ===================================================== | |
(philo (xs pred) | |
(if (eq? xs '()) false | |
(if (pred (car xs)) true | |
(this (second xs) pred)))) | |
;; ===================================================== | |
;; all | |
;; ===================================================== | |
(philo (xs pred) | |
(if (eq? xs '()) true | |
(if (pred (car xs)) (this (second xs) pred) | |
false))) | |
;; ===================================================== | |
;; index | |
;; ===================================================== | |
(philo (xs e idx) | |
(if (eq? xs '()) -1 | |
(if (eq? (car xs) e) idx | |
(this (second xs) e (+ idx 1))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment