Skip to content

Instantly share code, notes, and snippets.

@kephas
Last active March 21, 2019 14:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kephas/bcc8a0315f95058fa5a8aa78ff79ea80 to your computer and use it in GitHub Desktop.
Save kephas/bcc8a0315f95058fa5a8aa78ff79ea80 to your computer and use it in GitHub Desktop.
Padded binary numbers in Common Lisp
(defun read-only-chars (stream chars)
(with-output-to-string (result)
(loop while (find (peek-char nil stream) chars)
do (princ (read-char stream) result))))
(set-dispatch-macro-character #\# #\! (lambda (stream subchar arg)
(parse-integer (remove #\_ (read-only-chars stream "01_")) :radix 2)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment