Created
October 27, 2013 23:26
-
-
Save mmontone/7189175 to your computer and use it in GitHub Desktop.
Implementation of syntax for symbols to be able to use spaces instead of '-' in them.
The default enclosing chars are '<' and '>'.
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
| ;; Implementation of syntax for symbols to be able to use spaces instead of '-' in them. | |
| ;; The default enclosing chars are '<' and '>'. | |
| ;; Example: | |
| ;; (defclass <My Class> (<Standard Object>) | |
| ;; ((<My Slot> :accessor <My Slot> | |
| ;; :initarg :my-slot))) | |
| ;; | |
| ;; (<with slots> (<My slot>) | |
| ;; (<make instance> '<My class> :my-slot "Value") | |
| ;; (print <My slot>)) | |
| (defpackage symbol-syntax | |
| (:use cl)) | |
| (in-package symbol-syntax) | |
| (defvar *original-readtable* nil) | |
| (defvar *symbol-macro-open-char* #\<) | |
| (defvar *symbol-macro-close-char* #\>) | |
| (defmacro enable-symbol-reader-syntax () | |
| `(eval-when (:compile-toplevel :load-toplevel :execute) | |
| (%enable-symbol-reader-syntax))) | |
| (defun %enable-symbol-reader-syntax () | |
| (unless *original-readtable* | |
| (setf *original-readtable* *readtable* | |
| *readtable* (copy-readtable)) | |
| (set-macro-character *symbol-macro-open-char* | |
| (lambda (str char) | |
| (declare (ignore char)) ; Ignore me some warnings | |
| (let ((keep-going t)) | |
| (set-macro-character *symbol-macro-close-char* | |
| (lambda (stream char) | |
| (declare (ignore char) (ignore stream)) | |
| (setf keep-going nil))) | |
| (let ((symbol-parts | |
| (loop for thing = (read str nil nil t) | |
| while keep-going | |
| collect thing))) | |
| (intern (format nil "~{~a~^-~}" symbol-parts))))))) | |
| (values)) | |
| (defmacro disable-symbol-reader-syntax () | |
| `(eval-when (:compile-toplevel :load-toplevel :execute) | |
| (%disable-symbol-reader-syntax))) | |
| (defun %disable-symbol-reader-syntax () | |
| (when *original-readtable* | |
| (setf *readtable* *original-readtable* | |
| *original-readtable* nil)) | |
| (values)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment