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 (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))))) |
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
;;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)) | |
'() |
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
;; capitalize | |
M-c | |
M-- M-c | |
;; Upper case | |
M-u | |
M-- M-u | |
;; lower case | |
M-l | |
M-- M-l |
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
;; quit message | |
(fset 'yes-or-no-p 'y-or-n-p) | |
;;把缺省的 major mode 设置为 text-mode, 而不是几乎什么功能也 | |
;;没有的 fundamental-mode. | |
(setq default-major-mode 'text-mode) | |
(setq initial-major-mode 'text-mode) | |
;;光标靠近鼠标指针时,让鼠标指针自动让开,别挡住视线。 | |
(mouse-avoidance-mode 'animate) | |
;;显示列号 | |
(setq column-number-mode t) |
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 (memq item x) | |
(cond ((null? x) false) | |
((eq? item (car x)) x) | |
(else (memq item (cdr x))))) | |
;; huffman coding (information theory) | |
(define (make-leaf symbol weight) | |
(list 'leaf symbol weight)) | |
(define (leaf? object) | |
(eq? (car object) 'leaf)) | |
(define (symbol-leaf x) (cadr 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
;; 3.1 | |
(define (make-accumulator init) | |
(lambda (x) | |
(set! init (+ init x)) | |
init)) | |
;; 3.2 | |
(define (make-monitored f) | |
(let ((count 0)) | |
(lambda (m) | |
(cond ((eq? m 'how-many-calls) count) |
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 (random-in-range low high) | |
(let ((range (- high low))) | |
(+ low (random range)))) | |
(define (experiment x1 x2 y1 y2) | |
(let ((a (random-in-range x1 x2)) | |
(b (random-in-range y1 y2)) | |
(c (/ (+ x1 x2) 2.0)) | |
(d (/ (+ y1 y2) 2.0)) | |
(r (/ (- x1 x2) 2.0))) | |
(<= (+ (square (- a c)) |
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
;; selectors | |
(define (front-ptr queue) (car queue)) | |
(define (rear-ptr queue) (cdr queue)) | |
(define (set-front-ptr! queue item) (set-car! queue item)) | |
(define (set-rear-ptr! queue item) (set-cdr! queue item)) | |
(define (empty-queue? queue) (null? (front-ptr queue))) | |
;; constructors | |
(define (make-queue) (cons '() '())) | |
;; selectors | |
(define (front-queue queue) |
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-queue) | |
(let ((front-ptr '()) | |
(rear-ptr '())) | |
(define (set-front-ptr! item) | |
(set! front-ptr item)) | |
(define (set-rear-ptr! item) | |
(set! rear-ptr item)) | |
(define (empty-queue?) | |
(null? front-ptr)) | |
;; (define (print-queue) |
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
(load "stream-map.ss") | |
(load "ex59") | |
(define (scale-stream s f) | |
(stream-map (lambda (x) (* x f)) s)) | |
(define (mul-series s1 s2) | |
(cons-stream (* (stream-car s1) | |
(stream-car s2)) | |
(add-streams | |
(scale-stream (stream-cdr s2) (stream-car s1)) |