Skip to content

Instantly share code, notes, and snippets.

Reader Macros in Common Lisp

Reader macros are perhaps not as famous as ordinary macros. While macros are a great way to create your own DSL, reader macros allow even greater flexibility by allowing you to create entirely new syntax on top of Lisp.

Paul Graham explains them very well in [On Lisp][] (Chapter 17, Read-Macros):

The three big moments in a Lisp expression's life are read-time, compile-time, and runtime. Functions are in control at runtime. Macros give us a chance to perform transformations on programs at compile-time. ...read-macros... do their work at read-time.

Macros and read-macros see your program at different stages. Macros get hold of the program when it has already been parsed into Lisp objects by the reader, and read-macros operate on a program while it is still text. However, by invoking read on this text, a read-macro can, if it chooses, get parsed Lisp objects as well. Thus read-macros are at least as powerful as ordinary macros.

@priyadarshan
priyadarshan / ingest.sh
Last active August 29, 2015 13:57
Ingest media from DVD-ROM into increasing numbered folder
#!/bin/bash
# name of target disk
HD="mini2"
# path to target directory, do NOT start nor end with /
TARGETDIR="disks"
# which device is the DVD-ROM drive
ROMDRIVE="/dev/disk6"
(require 'ido-at-point)
(defun ido-at-point-x-prompt (prompt choices &optional display-fn)
"Display choices in a x-window prompt."
(when (and window-system choices)
(let ((chosen
(let (menu d) ;; d for display
(dolist (c choices)
(setq d (or (and display-fn (funcall display-fn c))
c))
import os
import re
import shutil
import sys
TITLE_RE = re.compile(r"^\s*#\+TITLE:\s*([^\n]+)\n")
PROPERTIES_RE = re.compile(r"^\n?[ \t]*:PROPERTIES:[ \t]*\n", re.MULTILINE)
END_RE = re.compile(r"^[ \t]*:END:[ \t]*\n\n", re.MULTILINE)
PROPERTY_RE = re.compile(r"^[ \t]*:[\w\-]+:[^\n]*\n", re.MULTILINE)
ITALICS_RE = re.compile(r"^/([^\n]+)/", re.MULTILINE)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; This script works with GNU CLISP but may not work with other
;; implementations since the restarts which are provided are
;; implementation dependant. This will *not* work when compiled
;; since CLISP removes the use-value restart in compiled code.
;;
;; This script also uses quicklisp to load several third party
;; libraries (see http://www.quicklisp.org)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
————————————————————————————————————————————————————————————————————————————————————————————————————
BBEDIT/TEXTWRANGLER REGULAR EXPRESSION GUIDE MODIFIED 2014-01-13 : 00:12
————————————————————————————————————————————————————————————————————————————————————————————————————
NOTES:
The PCRE engine (Perl Compatible Regular Expressions) is what BBEdit and TextWrangler use.
Items I'm unsure of are marked '# PCRE?'. The list while fairly comprehensive is not complete.
;; Description: Emacs functions to display a list of all faces currently used in open buffers
;; Author: Jordon Biondo
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; This program is free software; you can redistribute it and/or
;; modify it under the terms of the GNU General Public License as
;; published by the Free Software Foundation; either version 3, or
;; (at your option) any later version.
;;
(require 'recentf)
;; Implement functionality similar to uniquify to make recentf results bearable
;; Requires s.el and dash.el - awesome libraries from Magnar Sveen
;; Hat-tip : Baishampayan Ghose for the clojure implementation at
;; https://gist.github.com/ghoseb/8432086
(require 's)
(require 'dash)
(require 'recentf)
;; Implement functionality similar to uniquify to make recentf results bearable
;; Requires s.el and dash.el - awesome libraries from Magnar Sveen
;; Hat-tip : Baishampayan Ghose for the clojure implementation at
;; https://gist.github.com/ghoseb/8432086
(require 's)
(require 'dash)
(require 'recentf)
;; Implement functionality similar to uniquify to make recentf results bearable
;; Requires s.el and dash.el - awesome libraries from Magnar Sveen
;; Hat-tip : Baishampayan Ghose for the clojure implementation at
;; https://gist.github.com/ghoseb/8432086
(require 's)
(require 'dash)