Starting from:

$34.99

CSCI312 Homework 4- Jabberwocks Solution


• A borogove is either:
• A jubjub is either:
• A tove is
1
Types: Write definitions of jabberwocks, borogoves, jubjubs, and toves in Racket language plai using define-type.
Conversion to and from lists: Use your datatype to write a procedure that converts jabberwocks to lists. For example:
> [.pretty-print (jabberwock-to-list test-case))
‘(jabberwock snark
(borogove bloom
(jubjub blub
(jubjub flub (tove pair 1 2))
(borogove barn (borogove bunny (tove pair 3 1)) (tove pair 2 1))) (jubjub flub (tove pair 1 1)))
(borogove bunny (tove pair 1 0)))
1
2
3
4
5
6
7
8
9
10
11
Note that the returned object is just a list of lists, symbols, and numbers.
Also write a procedure list-to-jabberwock that takes a list, like the one output by jabberwock-to-list, and converts it into a genuine jabberwock.
Counting jubjubs and borogoves: Also write a procedure fix-toves that copies the jabberwock, and replaces each pair of tove numbers with the number of borogoves and the number of jubjubs in the path to the root. This is true in the jabberwock shown above.
Test cases: Add enough unit tests to demonstrate all features of your procedures. These can be in the same file or a separate file.
Turn in: Put all your files into a folder csci312hw04yourname, zip it, and submit to canvas.

More products