Skip to content

Instantly share code, notes, and snippets.

View ashok-khanna's full-sized avatar
🏠
Working from home

Ashok Khanna ashok-khanna

🏠
Working from home
View GitHub Profile
@ashok-khanna
ashok-khanna / _reader-macros.md
Created August 25, 2021 17:52 — 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.

(ql:quickload '("clack" "lack" "lack-middleware-mount" "cl-dotenv" "quri" "uuid" "dexador" "jsown"))
(defpackage #:example
(:use #:common-lisp))
(in-package #:example)
(.env:load-env (merge-pathnames ".env"))
(defvar *okta-authorize-uri* (quri:uri (uiop:getenv "OKTA_AUTHORIZE_URI")))
(defun make-url-part (title)
"Generate a url-part from a title. A url-part should only have alphanumeric characters or dashes (in place of spaces)."
(string-downcase
(delete-if #'(lambda (x) (not (or (alphanumericp x) (char= #\- x))))
(substitute #\- #\Space title))))