function which builds, from a list, a list without the eleme

You have problems, and we're glad to hear them. Explain the problem, what you have tried, and where you got stuck.
Feel free to share a little info on yourself and the course.
Forum rules
Please respect your teacher's guidelines. Homework is a learning tool. If we just post answers, we aren't actually helping. When you post questions, be sure to show what you have tried or what you don't understand.
Post Reply
Pytty55
Posts: 1
Joined: Sat Aug 18, 2018 12:55 am

function which builds, from a list, a list without the eleme

Post by Pytty55 » Sat Aug 18, 2018 1:14 am

I'm trying to write a function which builds, from a list, a list without the elements
that begin with a given letter, and by using char and string; example:

Code: Select all

(remove 'n '(nose naked retired art friend)) ==> (art friend retired)
What I did so far :

Code: Select all

(defun my-remove (r list)
(cond
((not list) nil)
((equal (char (string (car list))0)#R)(my-remove r(cdr list)))
(t (cons (car list) (my-remove r(cdr list)))) ) )
But keeps returning :

Code: Select all

(remove 'n '(nose naked retired art friend)) ==> (NOSE NAKED ART FRIEND)
What did I miss ?

nuntius
Posts: 538
Joined: Sat Aug 09, 2008 10:44 am
Location: Newton, MA

Re: function which builds, from a list, a list without the e

Post by nuntius » Sat Aug 18, 2018 3:55 am

Things to look at / fix:
  • called REMOVE instead of MY-REMOVE
  • hard-coded #\R instead of using the passed parameter
  • pass a character to remove instead of a quoted symbol (#\r vs 'r)
  • run (string 'nose) and look at the capitalization of the result
P.S. The forum strips backslashes. Double-backslash is converted to single backslash. Every preview or submit does another strip, so be careful.

Post Reply