2
votes

Background

I'm writing a Common Lisp library containing a reader macro. Now it concerns me that my reader macro may overwrite existing one which has the same dispatching macro character. To avoid this conflict, I want to provide some way for users to control whether my reader macro should be defined or not from outside of the library.

The special variable *features* seems to serve this purpose, evaluating

(push :some-suppression-flag *features*)

before loading the library and

#-some-suppression-flag (set-dispatch-macro-character ...)

in the library.

I know Named Readtables can solve the "global readtable problem", but I don't want to use it to make my library have few dependencies.

Question

Is the above way using *features* a good manner to pass some options to a library at load/compile time? Or are there common practice to do so?

1
I'd have a function to install the reader macros to a given readtable. See for example FSet or SERIES. - jkiiski
Thank you for your comment. The libraries seem to contain many useful techniques to create Common Lisp libraries. I'll check them out. - magnon

1 Answers

4
votes

Just provide a function which the user can call:

(defun enable-foo-syntax (&optional (enabled-p t))
  ...)

(enable-foo-syntax t)    ; on
(enable-foo-syntax nil)  ; off