(wat-aro)

生きてます

2015-11-05から1日間の記事一覧

SICP 問題 3.3

(define (make-account balance password) (define (withdraw amount) (if (>= balance amount) (begin (set! balance (- balance amount)) balance) "Insufficient funds")) (define (deposit amount) (set! balance (+ balance amount)) balance) (define …

SICP 問題 3.2

(define (make-monitored f) (let ((mf 0)) (lambda (in) (cond ((eq? in 'how-many-calls?) mf) ((eq? in 'reset-count) (set! mf 0)) (else (set! mf (+ 1 mf)) (f in)))))) gosh> (define s (make-monitored sqrt)) s gosh> (s 100) 10 gosh> (s 'how-man…

SICP 問題 3.1

(define (make-accumulator n) (let ((sum n)) (lambda (num) (set! sum (+ sum num)) sum))) gosh> (define A (make-accumulator 5)) A gosh> (A 10) 15 gosh> (A 10) 25

SICP 問題 2.91

(define (div-terms L1 L2) (if (empty-termlist? L1) (list (the-empty-termlist) (the-empty-termlist)) (let ((t1 (first-term L1)) (t2 (first-term L2))) (if (> (order t2) (order t1)) (list (the-empty-termlist) L1) (let ((new-c (div (coeff t1) …

SICP 問題 2.89

;; 2.89 ;; 濃い多項式に適している実装 (define (make-polynomial valiable term-list) (cons valiable term-list)) (define (valiable p) (car p)) (define (term-list p) (cdr p)) (define (valiable? v) (symbol? v)) (define (same-valiable? v1 v2) (a…