Question

Lisp program count-of (symbol list): Write a function named count-of that takes two parameters, a symbol...

Lisp program

count-of (symbol list): Write a function named count-of that takes two parameters, a symbol and a list. Count the number of instances of x in the list. Do not count the number of x in any sub-lists within the list.


Test: count-of 'a '(a 'a(a c) d c a).

Result: 2

trim-to (symbol list): Write a function named trim-to that takes a symbol and list as parameters. Return a new list starting from the first occurrence of the input symbol in the input list. If there is no occurrence of the symbol, return nil.

Test: trim-to 'c '(a b c d e)

Result: (C D E)

0 0
Add a comment Improve this question Transcribed image text
Answer #1

(defun count-of (symbol l)
(if (null l)
0
(if (equal (car l) symbol)
(+ 1 (count-of symbol (cdr l)))
(count-of symbol (cdr l))
)
)
)

(defun trim-of(symbol l)
(if (null l)
l
(if (equal (car l) symbol)
l
(trim-of symbol (cdr l))
)
)
)

Add a comment
Know the answer?
Add Answer to:
Lisp program count-of (symbol list): Write a function named count-of that takes two parameters, a symbol...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT