chickadee » srfi-1 » append-reverse!

append-reverse rev-head tailprocedure
append-reverse! rev-head tailprocedure

append-reverse returns (append (reverse REV-HEAD) TAIL). It is provided because it is a common operation -- a common list-processing style calls for this exact operation to transfer values accumulated in reverse order onto the front of another list, and because the implementation is significantly more efficient than the simple composition it replaces. (But note that this pattern of iterative computation followed by a reverse can frequently be rewritten as a recursion, dispensing with the reverse and append-reverse steps, and shifting temporary, intermediate storage from the heap to the stack, which is typically a win for reasons of cache locality and eager storage reclamation.)

append-reverse! is just the linear-update variant -- it is allowed, but not required, to alter REV-HEAD's cons cells to construct the result.