removing last element of a list(scheme)
问题 So I have to remove the last element of a list in scheme. For example, let's say I have a list (1 2 3 4) . I need to return: (1 2 3) My idea: reverse(list) car(list) reverse(list) Is there a reverse function in scheme(racket)? 回答1: You wrote: "reverse, car, reverse". I believe you meant to write "reverse, cdr, reverse". There's nothing wrong with this solution; it's linear in the size of the list, just like any solution to this that uses the standard lists. As code: ;; all-but-last: return