Skip to content

Instantly share code, notes, and snippets.

@phmarek
Created July 6, 2020 11:31
Show Gist options
  • Save phmarek/5efca753394112c40a32905fd30c8ef9 to your computer and use it in GitHub Desktop.
Save phmarek/5efca753394112c40a32905fd30c8ef9 to your computer and use it in GitHub Desktop.
A reader macro like qw() in Perl
(defpackage :perl-symbols)
(defun my-qw-reader (stream char)
(declare (ignore char))
(let ((*readtable* (copy-readtable nil))
(*package* (find-package :perl-symbols)))
(setf (readtable-case *readtable*)
:preserve)
(set-macro-character #\: nil nil *readtable*)
(labels ((r (x)
(typecase x
(null x)
(symbol (symbol-name x))
(cons (cons (r (car x))
(r (cdr x))))
(T x))))
(r (read stream)))))
(set-macro-character #\§ #'my-qw-reader)
(list 1 2 §FooBar `§(OMG it is full (of Strings!)))
; (1 2 "FooBar" ("OMG" "it" "is" "full" ("of" "Strings!")))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment