Add Exercise 4.49
This commit is contained in:
parent
43d230f0e6
commit
804d66afdb
|
@ -24,6 +24,11 @@
|
|||
(set! *unparsed* (cdr *unparsed*))
|
||||
(list (car word-list) found-word)))
|
||||
|
||||
(define (generate-word word-list)
|
||||
(let ((word-type (car word-list)))
|
||||
(amb (list word-type (cadr word-list))
|
||||
(parse-word (cons word-type (cdr (cdr word-list)))))))
|
||||
|
||||
(define *unparsed* '())
|
||||
|
||||
(define (parse input)
|
||||
|
@ -208,3 +213,72 @@
|
|||
;; infinite loop, as the first clause immediately calls
|
||||
;; parse-verb-phrase recursively. There is nothing to limit this
|
||||
;; recursion.
|
||||
|
||||
|
||||
;; Exercise 4.49
|
||||
|
||||
;;; Amb-Eval input:
|
||||
(set! parse-word generate-word)
|
||||
|
||||
;;; Starting a new problem
|
||||
|
||||
|
||||
;;; Amb-Eval value:
|
||||
0
|
||||
ok
|
||||
|
||||
;;; Amb-Eval input:
|
||||
(parse '())
|
||||
|
||||
;;; Starting a new problem
|
||||
|
||||
|
||||
;;; Amb-Eval value:
|
||||
0
|
||||
(simple-sentence (simple-noun-phrase (article the) ((noun student))) (verb studies))
|
||||
|
||||
;;; Amb-Eval input:
|
||||
try-again
|
||||
|
||||
|
||||
;;; Amb-Eval value:
|
||||
6
|
||||
(compound-sentence (simple-sentence (simple-noun-phrase (article the) ((noun student))) (verb studies)) (connective and) (simple-sentence (simple-noun-phrase (article the) ((noun student))) (verb studies)))
|
||||
|
||||
;;; Amb-Eval input:
|
||||
try-again
|
||||
|
||||
|
||||
;;; Amb-Eval value:
|
||||
10
|
||||
(compound-sentence (compound-sentence (simple-sentence (simple-noun-phrase (article the) ((noun student))) (verb studies)) (connective and) (simple-sentence (simple-noun-phrase (article the) ((noun student))) (verb studies))) (connective and) (simple-sentence (simple-noun-phrase (article the) ((noun student))) (verb studies)))
|
||||
|
||||
;;; Amb-Eval input:
|
||||
try-again
|
||||
|
||||
|
||||
;;; Amb-Eval value:
|
||||
14
|
||||
(compound-sentence (compound-sentence (compound-sentence (simple-sentence (simple-noun-phrase (article the) ((noun student))) (verb studies)) (connective and) (simple-sentence (simple-noun-phrase (article the) ((noun student))) (verb studies))) (connective and) (simple-sentence (simple-noun-phrase (article the) ((noun student))) (verb studies))) (connective and) (simple-sentence (simple-noun-phrase (article the) ((noun student))) (verb studies)))
|
||||
|
||||
;;; Amb-Eval input:
|
||||
try-again
|
||||
|
||||
|
||||
;;; Amb-Eval value:
|
||||
18
|
||||
(compound-sentence (compound-sentence (compound-sentence (compound-sentence (simple-sentence (simple-noun-phrase (article the) ((noun student))) (verb studies)) (connective and) (simple-sentence (simple-noun-phrase (article the) ((noun student))) (verb studies))) (connective and) (simple-sentence (simple-noun-phrase (article the) ((noun student))) (verb studies))) (connective and) (simple-sentence (simple-noun-phrase (article the) ((noun student))) (verb studies))) (connective and) (simple-sentence (simple-noun-phrase (article the) ((noun student))) (verb studies)))
|
||||
|
||||
;;; Amb-Eval input:
|
||||
try-again
|
||||
|
||||
|
||||
;;; Amb-Eval value:
|
||||
23
|
||||
(compound-sentence (compound-sentence (compound-sentence (compound-sentence (compound-sentence (simple-sentence (simple-noun-phrase (article the) ((noun student))) (verb studies)) (connective and) (simple-sentence (simple-noun-phrase (article the) ((noun student))) (verb studies))) (connective and) (simple-sentence (simple-noun-phrase (article the) ((noun student))) (verb studies))) (connective and) (simple-sentence (simple-noun-phrase (article the) ((noun student))) (verb studies))) (connective and) (simple-sentence (simple-noun-phrase (article the) ((noun student))) (verb studies))) (connective and) (simple-sentence (simple-noun-phrase (article the) ((noun student))) (verb studies)))
|
||||
|
||||
;;; Amb-Eval input:
|
||||
|
||||
|
||||
;; The generation gets stuck in the outer-most recursion. In this
|
||||
;; case, it is the generation of compound sentences from simple sentences.
|
||||
|
|
Loading…
Reference in New Issue