Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Types and Specs

Type Definitions:

;; Simple type alias
(deftype byte () (integer 0 255))

;; Parameterized type
(deftype list (a) (list a))

;; Union type
(deftype number () (union integer float))

;; Record type
(deftype person ()
  (tuple 'person
         string    ; name
         integer)) ; age

Function Specs:

;; Simple spec
(defun add
  {(spec [[integer integer] integer])}
  ([x y] (+ x y)))

;; Multiple clauses
(defun process
  {(spec [[atom] ok]
         [[atom any] {ok any}])}
  ([cmd] ...)
  ([cmd arg] ...))

;; With type variables
(defun id
  {(spec [[a] a])}
  ([x] x))