100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace

Common Lisp Cheat Sheet

Common Lisp Cheat Sheet

Essential Common Lisp syntax covering function and variable definitions, control flow, list operations, formatted output, and macros.

2 PagesIntermediateMar 25, 2026

Functions & Variables

Defining functions and global/local bindings.

lisp
(defun square (x)  (* x x))(defvar *count* 0)          ; global, special variable(defparameter *name* "Lisp") ; global, expects reassignment(let ((x 1) (y 2))          ; local bindings  (+ x y))(setf *count* (+ *count* 1))

Control Flow

Conditionals and iteration constructs.

lisp
(if (> x 0) "positive" "negative")(cond ((> x 0) "positive")      ((< x 0) "negative")      (t "zero"))(when (> x 0)  (print "positive"))(unless (> x 0)  (print "not positive"))(loop for i from 1 to 5      do (print i))

List Operations

Core functions for working with lists.

  • (car lst)- returns the first element of a list
  • (cdr lst)- returns the list minus its first element
  • (cons a b)- constructs a new cons cell
  • (list a b c)- creates a new list from arguments
  • (mapcar #'fn lst)- applies fn to each element, returns a new list
  • (append lst1 lst2)- concatenates lists
  • (reverse lst)- returns a reversed copy of the list
  • (nth n lst)- returns the nth element (zero-indexed)

Format & I/O

The format function's most common directives.

lisp
(format t "Hello, ~a!~%" "World")   ; ~a = aesthetic, ~% = newline(format t "~d + ~d = ~d~%" 1 2 3)   ; ~d = decimal integer(format t "~s~%" "quoted")          ; ~s = write with slashify(format t "~,2f~%" 3.14159)         ; ~,2f = float, 2 decimal places

Macros

Defining simple code-transforming macros.

lisp
(defmacro my-if (test then else)  `(cond (,test ,then)         (t ,else)))(my-if (> 5 3) (print "yes") (print "no"))(defmacro while (test &body body)  `(loop while ,test         do (progn ,@body)))
Pro Tip

Use `defparameter` (not `defvar`) when you want redefining the source file to actually update the variable's value — `defvar` only sets it if it is not already bound, which is convenient for state but confusing during iterative development.

Was this cheat sheet helpful?

Explore Topics

#CommonLisp#CommonLispCheatSheet#Programming#Intermediate#FunctionsVariables#ControlFlow#ListOperations#FormatIO#Functions#DataStructures#CheatSheet#SkillVeris
Advertisement
Sri Hayavadhana Info-Tech

Professional Web Designing Services

  • Responsive Websites
  • E-commerce Solutions
  • SEO Friendly Design
  • Fast & Secure
  • Support & Maintenance
Get a Free Quote

Share this Cheat Sheet