Next: Using Lists as Sets, Previous: Modifying List Variables, Up: Lists [Contents][Index]
You can modify the CAR and CDR contents of a cons cell with the
primitives setcar and setcdr. These are destructive
operations because they change existing list structure.
Destructive operations should be applied only to mutable lists,
that is, lists constructed via cons, list or similar
operations. Lists created by quoting are part of the program and
should not be changed by destructive operations. See Mutability.
Common Lisp note: Common Lisp uses functions
rplacaandrplacdto alter list structure; they change structure the same way assetcarandsetcdr, but the Common Lisp functions return the cons cell whilesetcarandsetcdrreturn the new CAR or CDR.