Skip to content

Instantly share code, notes, and snippets.

View yao2030's full-sized avatar

yao2030 yao2030

  • Shanghai, China
View GitHub Profile
;; capitalize
M-c
M-- M-c
;; Upper case
M-u
M-- M-u
;; lower case
M-l
M-- M-l
;;sets as order lists
(define (element-of-set? x set)
(cond ((null? set) false)
((= x (car set)) true)
((< x (car set)) false)
(else (element-of-set? x (cdr set)))))
(define (intersection-set set1 set2)
(if (or (null? set1) (null? set2))
'()
(define (union-set set1 set2)
(cond ((null? set1) set2)
((null? set2) set1)
((element-of-set? (car set1) set2)
(union-set (cdr set1) set2))
(else
(cons (car set1) (union-set (cdr set1) set2)))))
;;; 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) '+)))
(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)
@yao2030
yao2030 / book.txt
Last active December 9, 2015 19:38
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
(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)))
(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)
(define (split op1 op2)
(lambda (painter n)
(if (= n 0)
painter
(let ((smaller ((split op1 op2) painter (- n 1))))
(op1 painter (op2 smaller smaller))))))
(define (up-split painter n)
(if (= n 0)
painter
(let ((smaller (up-split painter (- n 1))))
(below painter (beside smaller smaller)))))