Scheme: Iterative process to reconstruct a list in original order?
问题 My question is: how to write a procedure that utilises tailcall, and that constructs a list not in the reverse order. To show what I mean, here is an example of a very simple procedure that is iterative, and that creates a copy of a list: (define (copy-list ls) (define (iter cp-ls rest-ls) (if (null? rest-ls) cp-ls (iter (cons (car rest-ls) cp-ls) (cdr rest-ls)))) (iter '() ls)) The problem is that, due to the iterative order in which the elements are cons ed together, the returned list ends