Skip to content

Instantly share code, notes, and snippets.

@ahungry
ahungry / _reader-macros.md
Created May 19, 2016 01:21 — forked from chaitanyagupta/_reader-macros.md
Reader Macros in Common Lisp

Reader Macros in Common Lisp

This post also appears on lisper.in.

Reader macros are perhaps not as famous as ordinary macros. While macros are a great way to create your own DSL, reader macros provide 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.

@ahungry
ahungry / post.php
Created January 23, 2016 06:19
Safely get post data or defaults
<?php
function post($key, $default = '')
{
return isset($_POST[$key]) ? $_POST[$key] : $default;
}
$name = post('name', 'Jon Smith');
@ahungry
ahungry / gist:94c8e255d6931b1cb2af
Last active January 21, 2016 04:16
Caesar Cipher with Common Lisp Glyphs package
(ƒ caesar-cipher
α → (let ((n (or αb 11)))
(coerce (ψ (ψ (coerce α 'list)
α → (mod (- (+ (char-code α) n) 97) 26))
α → (code-char (+ 97 α))) 'string)))
Common Lisp using my package https://github.com/ahungry/glyphs