I want to create a keyword from a string.

Asked 2 years ago, Updated 2 years ago, 70 views

: I'd like to create a keyword called foo.

 (intern":FOO")

However, it appears that the symbol |:FOO| can be created. How can I create :foo?

common-lisp

2022-09-30 20:27

2 Answers

In the utility library, Alexandria has a function called make-keyword.

 (alexandria: make-keyword "FOO")
<=>: FOO
;   —EXTERNAL


2022-09-30 20:27

Intern in the keyword package with intern.

 (intern "FOO": keyword)
<=>: FOO

A symbol like ':foo' is an abbreviation for the symbol in the keyword package and can also be considered an abbreviation for 'keyword:foo', so you can create it by interning in the keyword package.

 (intern":FOO")

will only create the symbol |:FOO| under the current package.


2022-09-30 20:27

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.