Mutating functions and effects in Common Lisp

Table of Contents

Mutating functions and effects in Common Lisp

The main function for mutating data is setf, and the main form for calling side-effects is progn. But there are other forms which uses implicit progn as part of it’s body or uses setf under the hood. It’s not always easy to know when these forms are used.

Mutate variables

  • setf
  • incf
  • decf
  • setq

Destructive counterparts of non-destructive list functions

These functions are prefixed with n.

  • nreverse
  • nconc
  • nubst
  • nunion
  • nintersection
  • nset-difference

Other destructive list operations

These should have been prefixed with n, but are not due to historical reasons.

  • sort
  • delete (destructive remove – should be called nremove)
  • push
  • pop

Forms allowing more than one expression

While expressions with external effects are allowed everywhere, a good indication that side-effect are supported is the usage of progn or variants which allows more than one expression. The only reason to allow more than a single form is to run effects and throw away the result.

  • progn
  • prog1
  • prog2
  • block
  • prog
  • prog*
  • progv
  • tagbody

Date: 2022-08-08 Mon 00:00

Author: Simen Endsjø

Created: 2024-06-28 Fri 20:43