Append
Append
Main page

Append

logo
Community Hub0 subscribers
What are your thoughts?
Be the first to start a discussion here.
Be the first to start a discussion here.
Append

In computer programming, append is the operation for concatenating linked lists or arrays in some high-level programming languages.

Append originates in the programming language Lisp. The append procedure takes zero or more (linked) lists as arguments, and returns the concatenation of these lists.

Since the append procedure must completely copy all of its arguments except the last, both its time and space complexity are O(n) for a list of elements. It may thus be a source of inefficiency if used injudiciously in code.

The nconc procedure (called append! in Scheme) performs the same function as append, but destructively: it alters the cdr of each argument (save the last), pointing it to the next list.

Append can easily be defined recursively in terms of cons. The following is a simple implementation in Scheme, for two arguments only:

Append can also be implemented using fold-right:

Following Lisp, other high-level programming languages which feature linked lists as primitive data structures have adopted an append. To append lists, as an operator, Haskell uses ++, OCaml uses @.

Other languages use the + or ++ symbols to nondestructively concatenate a string, list, or array.

See all
User Avatar
No comments yet.