問題4.45 – SICP(計算機プログラムの構造と解釈)その218
問題4.45 (define (require p) (if (not p) (amb))) (define nouns ‘(noun student professor cat class)) (define verbs ‘(verb studies lectures eats sleeps)) (define articles ‘(article the a)) (define preposi…続きを読む
問題4.45 (define (require p) (if (not p) (amb))) (define nouns ‘(noun student professor cat class)) (define verbs ‘(verb studies lectures eats sleeps)) (define articles ‘(article the a)) (define preposi…続きを読む
Ubuntu 8.04 Hardy Heron で日本語入力を uim-anthy に変更するための手順メモ。 aptitude で uim-anthy のインストールを行う。 $ sudo aptitude install uim uim-anthy 設定ファイル uim-toolbar の修正を行う。 $ sudo vi /etc/X11/xinit/xinput.d/uim-toolbar …続きを読む
問題4.44 エイトクイーンパズルの問題。 8×8 の盤にしか対応していないけれど、これでよしとする。 あまりにも処理に時間がかかったので、こまめに distinct? を使うようにした。 (define (require p) (if (not p) (amb))) (define (queen-puzzle) (let ((q1 (amb 1 2 3 4 5 6 7 8))) (le…続きを読む
問題4.43 問題文には記載されていないが、Parker のヨット名が Mary Ann であることは自明。 よって、以下の様な関係がわかっている。 父 娘 ヨット Moore Mary Ann Lorna Downing Melissa Hall Rosalind Barnacle Hood Melissa Gabrielle Parker Mary A…続きを読む
問題4.42 amb 評価器に or が無かったので追加する。 (define (analyze exp) (cond ((self-evaluating? exp) ;; 省略 ((or? exp) (analyze (or->if exp))) ;; 省略 (else (error "Unknown expression type — ANALYZE" exp)))…続きを読む
file.util モジュールを使って、いろいろなディレクトリ操作をする。 (use file.util) ホームディレクトリを調べる (home-directory) gosh> "/Users/hoge" カレントディレクトリを調べる (current-directory) gosh> "/Users/hoge" ディレクトリを移動する 移動…続きを読む
メールヘッダなどで利用される RFC2822 (RFC822) 形式の日時文字列を Gauche の <date> オブジェクトに変換する方法。 (use rfc.822) (rfc822-date->date "Date: Sun, 28 Jun 2009 08:27:59 +0900") gosh> #<date 2009/06/28 08:2…続きを読む
問題4.41 手を抜いて、順列リストの生成には Gauche の permutations 手続き(Gauche ユーザリファレンス: 11.41 util.combinations – 組み合わせ)を利用する。 (use srfi-1) ; for filter (use util.combinations) ; for permutations (define (multiple-…続きを読む
問題4.39 制限の順序は解には影響しない。 解を見いだす時間は、計算に失敗する場合が多い条件を上にすると速くなる。 問題4.40 (define (multiple-dwelling) (let ((backer (amb 1 2 3 4 5))) (require (not (= backer 5))) (let ((cooper (amb 1 2 3 4 5))) (require (not…続きを読む
問題4.38 p249 の multiple-dwelling 手続きの (require (not (= (abs (- smith fletcher)) 1))) 部分を削除するだけでよい。 (define (require p) (if (not p) (amb))) (define (multiple-dwelling) (let ((backer (amb 1 2 3 4 5)) (co…続きを読む