理系学生日記

おまえはいつまで学生気分なのか

2008-03-08から1日間の記事一覧

問題3-14 (3.3.1 Mutable List Structure)

mystery によって何が起こるでしょう! (define (mystery x) (define (loop x y) (if (null? x) y (let ((temp (cdr x))) (set-cdr! x y) (loop temp x)))) (loop x '())) (define v (list 'a 'b 'c 'd)) (define w (mystery v)) (print w) ; (d c b a) 見事…

問題3-13 (3.3.1 Mutable List Structure)

どうなるかって無限ループだよ >< 泣ける!!!! (define (last-pair x) (if (null? (cdr x)) x (last-pair (cdr x)))) (define (make-cycle x) (set-cdr! (last-pair x) x) x) (define z (make-cycle (list 'a 'b 'c))) (last-pair z) last-pair でずっとリ…

問題3-12 (3.3.1 Mutable List Structure)

set-car! と set-cdr! でリスト構造を変更することができるよ!!というおはなし.append と append! が以下のように定義されているとき, (define (append x y) (if (null? x) y (cons (car x) (append (cdr x) y)))) (define (append! x y) (set-cdr! (last-…