Common Lisp Programmatic Keyword

后端 未结 6 1067
我在风中等你
我在风中等你 2020-12-14 07:10

Is there a function in Common Lisp that takes a string as an argument and returns a keyword?

Example: (keyword \"foo\") -> :foo

6条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-14 07:46

    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")))
    

提交回复
热议问题