Exercise 4.48

Read Exercise 4.48 ~ Solution


I chose to add simple adverbs to my sentences.

(interpret '(define adverbs '(adverb noisily quickly loudly)))

(interpret '(define (parse-verb-phrase)
              (define (maybe-extend verb-phrase)
                (amb verb-phrase
                     (maybe-extend (list 'verb-phrase
                                         verb-phrase
                                         (parse-prepositional-phrase)))))
              (maybe-extend (parse-simple-verb-phrase))))

(interpret '(define (parse-simple-verb-phrase)
              (amb (list 'simple-verb-phrase
                         (parse-word verbs))
                   (list 'adverb-phrase
                         (parse-word verbs)
                         (parse-word adverbs)))))

;;; Amb-Eval input:
(parse '(the cat eats noisily in the class with the student))

;;; Starting a new problem 
;;; Amb-Eval value:
(sentence (simple-noun-phrase (article the) (noun cat)) (verb-phrase (verb-phrase (adverb-phrase (verb eats) (adverb noisily)) (prep-phrase (prep in) (simple-noun-phrase (article the) (noun class)))) (prep-phrase (prep with) (simple-noun-phrase (article the) (noun student)))))

;;; Amb-Eval input:
try-again

;;; Amb-Eval value:
(sentence (simple-noun-phrase (article the) (noun cat)) (verb-phrase (adverb-phrase (verb eats) (adverb noisily)) (prep-phrase (prep in) (noun-phrase (simple-noun-phrase (article the) (noun class)) (prep-phrase (prep with) (simple-noun-phrase (article the) (noun student)))))))

;;; Amb-Eval input:
try-again

;;; There are no more values of
(parse '(the cat eats noisily in the class with the student))

Leave a comment