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 (and->if exp) | |
(expand-and-clauses (and-clauses exp))) | |
(define (expand-and-clauses clauses) | |
(if (null? clauses) | |
true | |
(let ((first (car clauses)) | |
(rest (cdr clauses))) | |
(if (false? first) | |
'f | |
(make-if first (expand-and-clauses rest) false))))) |
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
def evaluatePoly(poly, x): | |
result = 0.0 | |
for i in range(len(poly)): | |
result += poly[i] * x ** i | |
return result | |
# poly = [0.0, 0.0, 5.0, 9.3, 7.0] | |
# x = -13 | |
# print evaluatePoly(poly, x) | |
def computeDeriv(poly): |
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)) |
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)) |
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
;; 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 (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
;; 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 (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
;; 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) |