Code · 1 file
Sample Common Lisp File
Common Lisp with defstruct, reduce and format directives. Every language sample implements the same small program so you can compare them side by side.
Common Lisp · 751 B
Sample Common Lisp file
An idiomatic Common Lisp example — the same customer program (or, for hardware languages, a small counter design) we offer in every language.
CC0 · free for any use · Verified by an independent tool · Report a problem
;;;; Sample Common Lisp program — samplefiles.com
(defstruct customer id name balance)
(defun vip-p (c)
(>= (customer-balance c) 10000))
(defun total-balance (customers)
(reduce #'+ customers :key #'customer-balance))
(let ((customers (list (make-customer :id 1 :name "Ada" :balance 12500.0d0)
(make-customer :id 2 :name "Grace" :balance 830.5d0)
(make-customer :id 3 :name "Linus" :balance 10000.0d0))))
(dolist (c customers)
(let ((name (customer-name c)))
(format t "~A~A ~10,2F ~A~%"
name (make-string (- 6 (length name)) :initial-element #\Space)
(customer-balance c) (if (vip-p c) "VIP" ""))))
(format t "Total: ~,2F~%" (total-balance customers)))File details
Download from the command line
curl -L -o sample.lisp https://files.samplefiles.com/code/lisp/sample.lispwget https://files.samplefiles.com/code/lisp/sample.lisphttps://files.samplefiles.com/code/lisp/sample.lispprintf '%s %s\n' 1baf2cdc74ab6718c54b4c2e573fd0ce69cd7706f082c5bf64e52ceace28ab57 sample.lisp | shasum -a 256 -cOr check the download in your browser with the checksum calculator.