This file contains hidden or 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
;; | |
(define (accumulate op init seq) | |
(if (null? seq) | |
init | |
(op (car seq) | |
(accumulate op init (cdr seq))))) | |
;; | |
(define (accumulate-n op init seqs) | |
(if (null? (car seqs)) | |
'() |
This file contains hidden or 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
(define (last-pair list1) | |
(if (= (length list1) 1) | |
(car list1) | |
(last-pair (cdr list1)))) | |
(define (but-last list1) | |
(if (= (length list1) 1) | |
'() | |
(cons (car list1) (but-last (cdr list1))))) | |
(define (reverse x) | |
(if (null? x) |
This file contains hidden or 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
(define (fold-left op initial sequence) | |
(define (iter result rest) | |
(if (null? rest) | |
result | |
(iter (op result (car rest)) | |
(cdr rest)))) | |
(iter initial sequence)) | |
(define fold-right accumulate) | |
(define (reverse seq) |
This file contains hidden or 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
(define (up-split painter n) | |
(if (= n 0) | |
painter | |
(let ((smaller (up-split painter (- n 1)))) | |
(below painter (beside smaller smaller))))) | |
This file contains hidden or 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
(define (split op1 op2) | |
(lambda (painter n) | |
(if (= n 0) | |
painter | |
(let ((smaller ((split op1 op2) painter (- n 1)))) | |
(op1 painter (op2 smaller smaller)))))) |
This file contains hidden or 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
(define (make-vect x y) | |
(cons x y)) | |
(define (xcor-vect v) | |
(car v)) | |
(define (ycor-vect v) | |
(cdr v)) | |
(define (add-vect v1 v2) | |
(make-vect (+ (xcor-vect v1) (xcor-vect v2)) | |
(+ (ycor-vect v1) (ycor-vect v2)))) | |
(define (sub-vect v1 v2) |
This file contains hidden or 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
(define (equal? list1 list2) | |
(cond ((null? list1) (null? list2)) | |
((null? list2) #f) | |
((eq? list1 list2) #t) | |
((eq? (car list1) (car list2)) (equal? (cdr list1) (cdr list2))) | |
(else #f))) |
This file contains hidden or 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
1. Paradigms of Artificial Intelligence Programming: Case Studies in Common Lisp | |
2. Code: The Hidden Language of Computer Hardware and Software | |
3. An introduction to algorithms | |
4. Artificial Intelligence: a modern approach | |
5. ON LISP | |
6. ANSI COMMON LISP | |
7. LISP IN SMALL PIECES | |
8. THE LITTLE LISPER | |
9. THE SEASONED SCHEMER |
This file contains hidden or 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
(define (=number? exp num) | |
(and (number? exp) (= exp num))) | |
(define (variable? x) (symbol? x)) | |
(define (same-variable? a b) | |
(and (variable? a) (variable? b) (eq? a b))) | |
(define (make-sum a1 a2) | |
(cond ((=number? a1 0) a2) |
This file contains hidden or 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
;;; SICP 2.58 part.b | |
;;; | |
;; sum | |
(define (make-sum a1 a2) | |
(cond ((and (number? a1) (number? a2)) (+ a1 a2)) | |
((=number? a1 0) a2) | |
((=number? a2 0) a1) | |
(else (list a1 '+ a2)))) | |
(define (sum? x) | |
(and (pair? x) (eq? (cadr x) '+))) |