2
votes

I want to build a macro that defines several classes and methods based on symbols that would have a root string (I guess this is not an unusual thing to do in lisp ^^).

dummy example : (defmacro define-my-stuff (term) would do such things as

  • defclass my-super-term-class
  • defvar *term-variable*
  • defun do-term ((a-thing *example-term*))
    with symbols built upon the "term" macro parameter

How to deal with the different readtable-case so the code can be universally used with the four different type of cases (:UPCASE :DOWNCASE :PRESERVE :INVERT).

I want to be able to use these symbols from source code. So I want the symbols created inside the macro to be built by the reader readtable-case rule that is used by the lisp system.

(The regular is :UPCASE but some uses :DOWNCASE for example).

The only way I have found to do such a thing would be to use the READ-FROM-STRING function (example : (read-from-string (concatenate "term" "-variable")) But this also interns the symbol as side effect.

So how should I compute a symbol following the readtable-case rule without interning it ?
Is there in function for that in the common-lisp package ?

2

2 Answers

5
votes

You can use an uninterned symbol as a string designator:

(string '#:Foo)
=> "FOO"
or=> "foo"
or=> "Foo"
or=> "fOO"
2
votes

You can create an uninterned symbol:

(read-from-string (concatenate 'string "#:" "term" "-variable")

But you need to be very careful with READ-FROM-STRING when trying to securely read from a not secure string. Common Lisp IIRC lacks a standard symbol parser which only does that operation in isolation - without read time evaluation and without reading arbitrary structures. There is probably in a library somewhere a 'secure' symbol parser, which the also checks the readtable case.