Created
July 6, 2020 11:31
-
-
Save phmarek/5efca753394112c40a32905fd30c8ef9 to your computer and use it in GitHub Desktop.
A reader macro like qw() in Perl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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