Detele duplicates from list
Detele duplicates from list
Hi , I am new to LISP and on my exam I had to write a function that I would pass a list as an argument and it would return a list without duplicates.
please help me
please help me
Re: Detele duplicates from list
Here are three approaches to identifying duplicates.
- Sort the list (like the old unix `sort file | uniq` trick)
- Search the output list (there's a CL command to only push new items)
- Use a hashtable
- Sort the list (like the old unix `sort file | uniq` trick)
- Search the output list (there's a CL command to only push new items)
- Use a hashtable
Re: Detele duplicates from list
we didn't learn hashtable.
we just learned elementary lisp an in this function we must use recursion only.
please help me and write a simple function.
we just learned elementary lisp an in this function we must use recursion only.
please help me and write a simple function.
Re: Detele duplicates from list
You've gotta learn using the documentation, 'i haven't learned it yet' is kindah a defeatist position, go learn it thenmisha1988 wrote:we didn't learn hashtable.
Admittedly, i don't understand all parts, and not everything is as well described. hash table at lispdoc. Essentially, make the hashtable with make-hash-table and then get/set elements with gethash, really straightforward, assuming you know how to make a 'global' variable (DEFVAR, DEFPARAMETER), and how to use SETF.
Re: Detele duplicates from list
First write a recursive function that can print each element of the list. (output is useful for testing)misha1988 wrote:please help me and write a simple function.
Then add an optional parameter called output; have it initialize to an empty list, and push each element onto it.
Then augment your function to only push when the element is new.
Then remove, comment out, or (when nil ...) the debug output.
If you get stuck, ask detailed questions or post what you have in
Code: Select all
Re: Detele duplicates from list
nuntius wrote:First write a recursive function that can print each element of the list. (output is useful for testing)misha1988 wrote:please help me and write a simple function.
Then add an optional parameter called output; have it initialize to an empty list, and push each element onto it.
Then augment your function to only push when the element is new.
Then remove, comment out, or (when nil ...) the debug output.
If you get stuck, ask detailed questions or post what you have inblocks so we can comment.Code: Select all
Sorry but I am new to LISP. I do know much of it . I just need to have the code of the function to show it to a lector
can you help me ?
Re: Detele duplicates from list
Or, if you want to be a smart-arse, (send-to-lector (constantly nil))...the specification only asked for the returned list have no duplicates, not that it have the same elements as the input otherwise, so there's no point wasting time looking at the argument: just return NIL -- that's a list with no duplicates!
Re: Detele duplicates from list
These functions are already writen I can't just send this link to lector
I should give him scource of a function that uses recursion :S
can anyone write it
help me, the deadline is in 3 days
Re: Detele duplicates from list
Try it.. post the attempt. Psuedocode will do.
Here is a hint: UNLESS the list is empty(NULL), put together(as in CONS) the FIRST of with: the REST of the list after the duplicates removed(this is the same function you're making at this point.) and the elements being the same to the FIRST of the list REMOVEd.
Where uppercase words are all the functions/macros used except the function in use. Anyway if that confuses you, put it out of your mind and write something you came up with. If you can't do it recursively.. then don't do it that way yet.
Here is a hint: UNLESS the list is empty(NULL), put together(as in CONS) the FIRST of with: the REST of the list after the duplicates removed(this is the same function you're making at this point.) and the elements being the same to the FIRST of the list REMOVEd.
Where uppercase words are all the functions/macros used except the function in use. Anyway if that confuses you, put it out of your mind and write something you came up with. If you can't do it recursively.. then don't do it that way yet.