SICP 読み (220) 4.3.2 非決定性プログラムの例

ちょっと机上ベースででっち上げてみた。

問題 4.48

(define adjectives '(adjective pretty cleanly luminous cool))

(define (parse-adjective-noun-phrase)
  (list 'adjective-noun-phrase
	(parse-word adjective)
	(parse-word nouns)))

(define (parse-noun-phrase)
  (define (maybe-extend noun-phrase)
    (amb noun-phrase
	 (maybe-extend (list 'noun-phrase
			     noun-phrase
			     (parse-prepositional-phrase)))))
  (maybe-extend (amb (parse-simple-noun-phrase)
		     (parse-adjective-noun-phrase))))

いいのかなぁ。なんかきちんとバックトラックしてくれそうになさげ。あるいは

(define (parse-simple-noun-phrase)
  (list 'simple-nou-phrase
	(amb (parse-word articles)
	     (parse-word adjectives))
	(parse-word nouns)))

ってやって、parse-noun-phrase は元のまま。ってこれも微妙か。

追記

駄目みたいです。こんなにさくっと答えが出た、とゆー部分でスデに駄目。

さらに

英語がデキん、ってのがもろバレだな。(とほほ

(define (parse-adjective-noun-phrase)
  (list 'adjective-noun-phrase
	(parse-word articles)
	(parse-word adjectives)
	(parse-word nouns)))

で形容詞を認識。大体試験する時に

(parse '(the cool professor lectures))

って自分で入力してるんだから勘違いに気付けよ、と。(とほほほ