ENSURE-GETHASH
[alexandria.git] / symbols.lisp
blobecb267c0ffd6cf6e2074285690c575357723d7ab
1 (in-package :alexandria)
3 (declaim (inline ensure-symbol))
4 (defun ensure-symbol (name &optional (package *package*))
5 "Returns a symbol with name designated by NAME, accessible in package
6 designated by PACKAGE. If symbol is not already accessible in PACKAGE, it is
7 interned there. Returns a secondary value reflecting the status of the symbol
8 in the package, which matches the secondary return value of INTERN.
10 Example: (ENSURE-SYMBOL :CONS :CL) => CL:CONS, :EXTERNAL"
11 (intern (string name) package))
13 (defun make-formatted-symbol (package name)
14 (case package
15 ((nil)
16 (make-symbol name))
17 ((t)
18 (intern name))
20 (intern name package))))
22 (declaim (inline format-symbol))
23 (defun format-symbol (package control &rest arguments)
24 "Constructs a string by applying ARGUMENTS to CONTROL as if by FORMAT, and
25 then creates a symbol named by that string. If PACKAGE is NIL, returns an
26 uninterned symbol, if package is T, returns a symbol interned in the current
27 package, and otherwise returns a symbol interned in the package designated by
28 PACKAGE."
29 (values
30 (make-formatted-symbol package (apply #'format nil control arguments))))
32 (defun make-keyword (name)
33 "Interns the string designated by NAME in the KEYWORD package."
34 (intern (string name) :keyword))
36 (defun make-gensym-list (length &optional x)
37 "Returns a list of LENGTH gensyms, each generated with a call to
38 GENSYM using (if provided) as the argument."
39 (loop repeat length
40 collect (gensym x)))