The Bottom Line: cons Is Expensive

The ability to create new data structures at runtime using cons is a uniquely valuable feature of Lisp.

However, the programmer should be aware that, whatever the implementation, cons is computationally expensive. As a rough rule of thumb, one can think of cons as taking 100 times as much time as a simple function such as +.

The moral: avoid unnecessary conses. For example, if a program has just consed up a list that is in the reverse of the desired order, use nreverse to reverse it with no additional conses.

Contents    Page-10    Prev    Next    Index