Compare commits
3 Commits
000edb7976
...
dfd65eed08
Author | SHA1 | Date |
---|---|---|
Oliver Payne | dfd65eed08 | |
Oliver Payne | 2caab6255f | |
Oliver Payne | a3b0a23812 |
|
@ -139,7 +139,8 @@
|
|||
|
||||
(sentence
|
||||
(simple-noun-phrase (article the) (noun professor))
|
||||
(verb-phrase (verb lectures)
|
||||
(verb-phrase
|
||||
(verb lectures)
|
||||
(prep-phrase (prep to)
|
||||
(noun-phrase (simple-noun-phrase (article the) (noun student))
|
||||
(prep-phrase (prep in)
|
||||
|
@ -151,3 +152,41 @@
|
|||
(article the)
|
||||
(noun cat)))))))))
|
||||
;; The professor lectures to the student, who is in the class with the cat
|
||||
|
||||
|
||||
;; Exercise 4.46
|
||||
|
||||
;; If amb evaluated its arguments in any order other than
|
||||
;; left-to-right, then the recursive maybe-extend rules would never
|
||||
;; terminate, as the second argument is a recursive call to the
|
||||
;; procedure. We rely on the recursion stopping at each decision
|
||||
;; point.
|
||||
;;
|
||||
;; Also, since parse has side-effects (namely, it removes a word from
|
||||
;; the input), it is important that we parse the different parts of
|
||||
;; the sentence in the correct order.
|
||||
|
||||
;; Exercise 4.47
|
||||
|
||||
(define (parse-verb-phrase level)
|
||||
(log (list 'parse-verb-phrase level))
|
||||
(amb (parse-word verbs)
|
||||
(list 'verb-phrase
|
||||
(parse-verb-phrase (+ level 1))
|
||||
(parse-prepositional-phrase (+ level 1)))))
|
||||
|
||||
;; In this case, if (parse-word verbs) fails, then we evaluate the 2nd
|
||||
;; argument, which calls parse-verb-phrase recursively, creating a new
|
||||
;; amb, which tries (parse-word verbs), which still fails. In the
|
||||
;; orinal procedure, we evaluate (parse-word verbs) once and bind it
|
||||
;; to verb-phrase. We then keep extending the phrase until it either
|
||||
;; succeeds or fails. If it fails, the whole amb call fails. The
|
||||
;; version here never fails because it keeps calling
|
||||
;; parse-verb-phrase, leading to an infinite recursion. The only case
|
||||
;; where this procedure works is when we pass it a valid verb phrase
|
||||
;; and don't try again (ie trigger a fail).
|
||||
|
||||
;; If we swap the order of the clauses in the amb, then we get an
|
||||
;; infinite loop, as the first clause immediately calls
|
||||
;; parse-verb-phrase recursively. There is nothing to limit this
|
||||
;; recursion.
|
||||
|
|
Loading…
Reference in New Issue