SICP Exercise 4.48

SICP Exercise 4.48

(define adjectives '(adjective nice tall diligent small white))

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

;;; Amb-Eval input:
(parse '(the tall professor lectures))

;;; Starting a new problem
;;; Amb-Eval value:
(sentence
 (simple-noun-phrase
  (article the)
  (adjective-noun (adjective tall) (noun professor)))
 (verb lectures))

;;; Amb-Eval input:
try-again

;;; There are no more values of
(parse (quote (the tall professor lectures)))

;;; Amb-Eval input:
(parse '(the nice tall professor lectures))

;;; Starting a new problem
;;; Amb-Eval value:
(sentence
 (simple-noun-phrase
  (article the)
  (adjective-noun (adjective nice)
                  (adjective-noun (adjective tall)
                                  (noun professor))))
 (verb lectures))

;;; Amb-Eval input:
try-again

;;; There are no more values of
(parse (quote (the nice tall professor lectures)))

;;; Amb-Eval input:
(parse '(the nice tall professor lectures
             to the diligent student in the small class
             with the white cat))
; It works.  Output omitted
Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.