Common Lisp Programmatic Keyword
Here's a make-keyword
function which packages up keyword creation process (intern
ing of a name into the KEYWORD
package). :-)
(defun make-keyword (name) (values (intern name "KEYWORD")))
The answers given while being roughly correct do not produce a correct solution to the question's example.
Consider:
CL-USER(4): (intern "foo" :keyword)
:|foo|
NIL
CL-USER(5): (eq * :foo)
NIL
Usually you want to apply STRING-UPCASE to the string before interning it, thus:
(defun make-keyword (name) (values (intern (string-upcase name) "KEYWORD")))
There is a make-keyword
function in the Alexandria library, although it does preserve case so to get exactly what you want you'll have to upcase the string first.
In this example it also deals with strings with spaces (replacing them by dots):
(defun make-keyword (name) (values (intern (substitute #\. #\space (string-upcase name)) :keyword)))