How would you update a list by removing the first item?
consider the following pseudocode
define remover
(list = cdr list))
or is there a more recommendable way of removing the first item in a list?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You nailed it, just write it as a procedure:
And use it like this (this creates a new binding, and is not an assignment):
Or like this (this defines a new list):
In any case, be aware that the original list passed as a parameter to
removerwill not be modified, instead a new list will be returned without the first element of the old list; that’s the way to operate on immutable linked lists, you should never assume that any modifications on a list will occur in-place.