Advanced Topics

54.1 Coalton: Static Typing in Common Lisp

Coalton provides Hindley–Milner type inference, type classes, algebraic data types, and pattern matching, compiled to efficient CL and interoperable with regular Lisp code. It's used in production at quantum computing companies.

(ql:quickload "coalton")
(coalton-toplevel
  (declare add-ints (Integer -> Integer -> Integer))
  (define (add-ints a b) (+ a b))

  (define-type (Tree :a)
    (Leaf)
    (Node (Tree :a) :a (Tree :a)))

  (declare tree-size ((Tree :a) -> Integer))
  (define (tree-size t)
    (match t
      ((Leaf) 0)
      ((Node l _ r) (+ 1 (+ (tree-size l) (tree-size r)))))))

(coalton (add-ints 2 3))                   ; 5

54.2 Other Advanced Topics

Lazy, optimizable sequence operations (Waters, CLtL2 appendix)

Nondeterministic programming and constraint solving Weak pointers / finalizers

sb-ext:make-weak-pointer, trivial-garbage (portable weak references and finalizers) Generalized booleans and places

define-modify-macro, defsetf, define-setf-expander Environment access

&environment, macroexpand with environments, cl-environments/introspect-environment Custom streams

trivial-gray-streams: define your own stream classes Custom hash table tests

ECL inside C/C++, ABCL inside Java, Clasp with C++ WebAssembly / JS

JSCL (CL in the browser), Valtan, experimental Wasm targets Quantum and numerics

Quil/quilc (Rigetti), MAGICL (matrix algebra) Logic and theorem proving ACL2, Shen-in-CL Live code reloading

Redefine functions/classes at runtime; update-instance-for-redefined-class