Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need help with the following lisp problem. If you have any questions please ask, thank you! . Write a function compr which takes a

I need help with the following lisp problem. If you have any questions please ask, thank you!
image text in transcribed
.
Write a function compr which takes a list and replaces each run longer than one with a sublist consisting of the count and the item which repeats. If the list has sublists, treat them as single items; don't change them or try to compress the sublists. If an item is not repeated, leave it unchanged, with one exception: an existing item is a sublist beginning with a positive number, and does not repeat, it should be changed to a pair with a repeate count of 1. For instance, a sublist (3 spoons) which does not repeat should be converted to (1 (3 spoons ) ). The purpose of this rule is to avoid confusion so it is possible to create a reliable decompress function which will always recreate the original list. Here are some examples: 1sp> (load "compr.lsp") compr lsp> (compr '(a bw goober goober ccc tom fred fred)) (a bw (2 goober) (3 c) tom (2 fred)) lsp> (compr '(nothing here to change)) (nothing here to change) lsp> (compr '((a bc)(a bc)(a bc) (def) (4 5 6) (-3 -5 ((3 (a bc)) (def) (1 (4 5 6)) (-3 -5 -7) 10 12) lsp> (compr '(thing thing (a b) (a b) (a b) (ba) thud wumpus ((2 thing) (3 (a b)) (ba) thud wumpus) 1sp> (compr '(oooh oooh oooh oooh oooh)) ((5 oooh)) Use the equal? function to decide if adjacent items are the same. (Don't use =, since is only for comparing numbers.) Write a function compr which takes a list and replaces each run longer than one with a sublist consisting of the count and the item which repeats. If the list has sublists, treat them as single items; don't change them or try to compress the sublists. If an item is not repeated, leave it unchanged, with one exception: an existing item is a sublist beginning with a positive number, and does not repeat, it should be changed to a pair with a repeate count of 1. For instance, a sublist (3 spoons) which does not repeat should be converted to (1 (3 spoons ) ). The purpose of this rule is to avoid confusion so it is possible to create a reliable decompress function which will always recreate the original list. Here are some examples: 1sp> (load "compr.lsp") compr lsp> (compr '(a bw goober goober ccc tom fred fred)) (a bw (2 goober) (3 c) tom (2 fred)) lsp> (compr '(nothing here to change)) (nothing here to change) lsp> (compr '((a bc)(a bc)(a bc) (def) (4 5 6) (-3 -5 ((3 (a bc)) (def) (1 (4 5 6)) (-3 -5 -7) 10 12) lsp> (compr '(thing thing (a b) (a b) (a b) (ba) thud wumpus ((2 thing) (3 (a b)) (ba) thud wumpus) 1sp> (compr '(oooh oooh oooh oooh oooh)) ((5 oooh)) Use the equal? function to decide if adjacent items are the same. (Don't use =, since is only for comparing numbers.)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Harness The Power Of Big Data The IBM Big Data Platform

Authors: Paul Zikopoulos, David Corrigan James Giles Thomas Deutsch Krishnan Parasuraman Dirk DeRoos Paul Zikopoulos

1st Edition

0071808183, 9780071808187

More Books

Students also viewed these Databases questions

Question

OUTCOME 6 Explain and give examples of diversity management.

Answered: 1 week ago

Question

2. What potential barriers would you encourage Samuel to avoid?

Answered: 1 week ago