2014年11月17日月曜日

開発環境

計算機プログラムの構造と解釈[第2版](ハロルド エイブルソン (著)、ジュリー サスマン (著)、ジェラルド・ジェイ サスマン (著)、Harold Abelson (原著)、Julie Sussman (原著)、Gerald Jay Sussman (原著)、和田 英一 (翻訳)、翔泳社、原書: Structure and Interpretation of Computer Programs (MIT Electrical Engineering and Computer Science)(SICP))の4(超言語的抽象)、4.4(論理型プログラミング)、4.4.4(質問システムの実装)、4.4.4.8(フレームと束縛)、問題 4.76.を解いてみる。

その他参考書籍

問題 4.76.

コード(BBEdit, Emacs)

sample75.scm

#!/usr/bin/env gosh
;; -*- coding: utf-8 -*-

(define (conjoin conjuncts frame-stream)
  (if (empty-conjunction? conjuncts)
      frame-stream
      (merge-frame (qeval (first-conjunct conjuncts)
                          frame-stream)
                   (conjoin (rest-conjuncts conjuncts)
                            frame-stream))))

(define (merge-frame frame-1 frame-2)
  (cond ((or (eq? frame-1 the-empty-stream)
             (eq? frame-2 the-empty-stream))
         the-empty-stream)
        ((equal? frame-1 frame-2) frame-1)
        (else
         (flatten-stream
          (stream-flatmap (lambda (frame)
                            (if (eq? (qeval (negate frame) frame-2)
                                     'failed)
                                frame
                                'failed))
                          frame-1)))))
        

0 コメント:

コメントを投稿