I am trying to remove members which exists in a string from a list consisting of those members.
Example:
String: "ABC"
List: ('A 'B 'C 'D)
To do: Remove first element of string from the list
To remove the the element from the string:
I am converting it to a list using:
(car (string->list"ABC")
This gives me character list and first element: #\A
But I do not get how I can remove it from the list as both values do not compare: the character and list values.
Tried this weird approach which did not work:
((eq? (make-string 1 (car (string->list"ABC"))) (car (list 'A 'B 'C 'D))))
Does not work as string value does not compare with the first list value.
How I can compare & remove the first string alphabet from the original list??
This is not true. A list can have strings as well as characters as its elements, no problem. You’re getting the error because you’re using
caron a string, not a list.Ok, here you’re calling
(string->list "ABC")which gives you a list containing the character A, B and C. Now you’re callingcaron that and get the character A back. Up to here there’s no problem.But then you’re calling
liston that character getting a list which only contains the character A and then uselist-stringto turn this into the string"A". This is still perfectly legal. But then you’re callingcaron the string"A"and that’s the error because you’re callingcaron a string, butcaronly accepts a list (well, any pair actually) as its argument.Since you’re trying to compare A against that first element of
('A 'B 'C 'D), i.e.'A, which is a symbol, you probably want to convert the string"A"into the symbol'A(or the symbol'Ainto the string"A"). To do this, you can use the functionstring->symbolinstead ofcar.Once you have the symbol
A, you can easily remove it from the list using thefilterfunction: