

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
A problem set for implementing a thesaurus abstraction in scheme programming language. It includes instructions for creating an entry abstraction with a word and a list of synonyms, adding entries to the thesaurus, looking up words in the thesaurus, and picking a random synonym for a word. The document also suggests using the provided 'simple-thesaurus' and 'full-thesaurus' for testing.
Typology: Exercises
1 / 3
This page cannot be seen from the preview
Don't miss anything!
"No, not the dinosaur" you explain to Ben Bitdiddle, "it allows you to look up related words." As usual, Ben Bitdiddle is trying to implement the wrong thing and it's your job to help him out.
A thesaurus is comprised of words and their synonyms. In order to simplify the implementation, we're going to write an abstraction for thesaurus entry, which contains a word and a list of its synonyms. Complete the constructors and selectors for the abstraction:
(define (make-entry word synonyms) to-be-completed) (define (entry-word entry) to-be-completed) (define (entry-synonyms entry) to-be-completed) ;; example usage: (define e (make-entry "victory" (list "conquest" "triumph" "win"))) (entry-word e) ;Value: "victory" (entry-synonyms e) ;Value: ("conquest" "triumph" "win")
A thesaurus is a list of entries. Of primary interest are two procedures: adding an entry to the thesaurus and looking a word up in the thesaurus. First, we'll implement adding entries:
(define empty-thesaurus nil)
(define (add-to-thesaurus entry thesaurus) to-be-completed) (define t (add-to-thesaurus (make-entry "ball" (list "globe" "orb" "rondure" "sphere")) empty-thesaurus)) ;Value: "t --> (("ball" ...))" (car t) ;Value: ("ball" ("globe" "orb" "rondure" "sphere")) (cdr t) ;Value: #f
Once you've gotten a working add-to-thesaurus, download and evaluate hw7code.scm. (See supporting files in the Assignments section.) This will give you two thesauri: simple-thesaurus
and full-thesaurus. The simple thesaurus is for simple testing, and the full version is for serious testing.
In order to look a word up in the thesaurus, we must search through the entries until we find one that matches. You should use string=? to compare strings. Remember to respect the entry abstraction. If the word is in the thesaurus, return the matching entry. If the word is not in the thesaurus, return false.
(define (lookup word thesaurus) to-be-completed) (lookup "victory" simple-thesaurus) ;Value: ("victory" ("conquest" "triumph" "win")) (lookup "defeat" simple-thesaurus) ;Value: #f
Supposing that you are given the procedure pick-random, which randomly picks an element of a list:
(define (pick-random lst) (if (null? lst) nil (list-ref lst (random (length lst)))))
Write the procedure transmogrify, which takes in a word and a thesaurus and returns one of the synonyms of the word, picked at random. If the word is not in the thesaurus, return the orginal word.