Karthik Divi
·4 min read

Common Lisp Online Compiler - Run Common Lisp Code Online

Common Lisp has been around since the 1980s and it still does things most modern languages cannot. The macro system operates on the AST directly -- you are not generating strings, you are transforming code as data. CLOS (the Common Lisp Object System) supports multiple inheritance and method combinations that languages designed decades later still lack. And the interactive development style, where you redefine functions in a running program and the changes take effect immediately, influenced everything from Clojure to Jupyter notebooks.

It also has a reputation for being hard to set up. SBCL, the most popular implementation, is fast but its REPL is bare. Most developers pair it with Emacs and SLIME or use Portacle. That is a lot of tooling to install before writing your first defun.

When an online Common Lisp compiler helps

An online compiler strips all that away. You get a working Common Lisp environment in a browser tab. For certain tasks, that is exactly right:

  • Testing a macro expansion without restarting your REPL
  • Trying out CLOS method dispatch
  • Sharing a working snippet when explaining a concept
  • Working through exercises from "Practical Common Lisp" or "Land of Lisp"
  • Quick prototyping before moving code into a real project
  • Reminding yourself how loop macro syntax works (because nobody remembers all of it)

Higher-order functions and closures

Common Lisp was doing functional programming before it was trendy. Functions are first-class values, closures capture their environment, and funcall/apply let you call function objects. Here is a practical example:

(defun make-counter (start step)
  "Returns a closure that counts from START by STEP"
  (let ((current start))
    (lambda ()
      (let ((value current))
        (setf current (+ current step))
        value))))

(defun take (n fn)
  "Call FN n times and collect results"
  (loop for i below n collect (funcall fn)))

;; Counter that starts at 0 and increments by 3
(let ((counter (make-counter 0 3)))
  (format t "First 5 values: ~a~%" (take 5 counter))
  (format t "Next 3 values: ~a~%" (take 3 counter)))

;; Using mapcar with lambda
(let ((numbers '(1 2 3 4 5)))
  (format t "Squared: ~a~%" (mapcar (lambda (x) (* x x)) numbers))
  (format t "Even? ~a~%" (mapcar #'evenp numbers)))

The make-counter function returns a closure that remembers current between calls. Each invocation updates the captured variable. This is the same pattern that JavaScript developers rediscovered twenty years later.

Notice the format function with its tilde directives -- ~a for aesthetic output, ~% for newline. It is like printf but more powerful and arguably stranger.

The macro system

What separates Common Lisp from most languages is that macros run at compile time and produce code. They do not just substitute text like C preprocessor macros. They receive code as structured data (lists), transform it, and return new code. This is homoiconicity in practice -- code is data, data is code.

The loop macro is itself a demonstration. That entire iteration sublanguage is implemented as a macro within Common Lisp.

AI history

Worth noting: Common Lisp was the language of AI research for decades. Expert systems, symbolic reasoning, early machine learning -- much of it was written in Lisp. The language's flexibility made it ideal for exploring ideas that did not have established patterns yet. The interactive development model meant researchers could modify running systems, test hypotheses, and iterate without restart cycles.

Common Lisp on OneCompiler

OneCompiler's Common Lisp environment runs SBCL in the browser. Write code, execute it, see results. No Emacs configuration, no Quicklisp setup.

Practical details:

  • Standard Common Lisp functions and macros are available
  • Output appears immediately after execution
  • Share programs via URL -- useful when discussing code in forums or Lisp communities
  • The interface stays minimal, which lets you focus on the code

Common Lisp rewards exploration. An online compiler lowers the barrier so you can start exploring sooner.

Try it here: Common Lisp Online Compiler on OneCompiler