Skip to content

Commit fc34681

Browse files
committed
utilities: add symbolify, finally
1 parent 573d1ef commit fc34681

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -2791,8 +2791,9 @@ This is used both by other hax and by other code I've written. Things in this s
27912791

27922792
Here is what it currently provides.
27932793

2794-
- `parse-docstring-body` parses the body of a function with possible documentation and declarations into three values: docstring, list of declarations and remaining forms.
2794+
- `parse-docstring-body` parses the body of a function with possible documentation and declarations into three values: docstring, list of declarations and remaining forms. With luck it now dies this correctly (the docstring and declarations can be intermingled).
27952795
- `parse-simple-body` is like `parse-docstring-body` but it does not handle docstrings & only returns two values.
2796+
- `symbolify` makes symbols by concatenating string designators, and optionally interns them. If its first argument is a package designator it will intern the result of concatenating the remaining string designators in that package. If it is `nil` it will return an uninterned symbol. This is a slightly odd argument convention but I can't think of a better one. Example: if `s` is the symbol `foo` then `(symbolify nil s "-P")` will return an uninterned symbol whose name is `FOO-P`.
27962797
- `with-names` binds variables to uninterned symbols with the same name by default: `(with-names (<foo>) ...)`will bind `<foo>` to a fresh uninterned symbol with name `"<FOO>"`. `(with-names ((<foo> foo)) ...)` will bind `<foo>` to a fresh uninterned symbol with name `"FOO"`.
27972798
- `thunk` makes anonymous functions with no arguments: `(thunk ...)` is `(lambda () ...)`.
27982799
- `thunk*` makes anonymous functions which take an arbitrary number of arguments and ignore them all.

VERSION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
10.2.1
1+
10.3.0

utilities.lisp

+14
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#:parse-docstring-body
88
#:parse-simple-body
99
#:with-names
10+
#:symbolify
1011
#:thunk
1112
#:thunk*
1213
#:valid-type-specifier-p
@@ -55,6 +56,19 @@ a list of forms."
5556
(values docstring (nreverse scled) tail)))))))
5657
(grovel doc/decls/forms nil '())))
5758

59+
(defun symbolify (where &rest things)
60+
"Make a symbol from string representations of THINGS, interning it if WHERE is given
61+
62+
The argument order is slightly odd, but it makes sense since you want
63+
to be able to provide as many arguments as you need."
64+
(declare (dynamic-extent things))
65+
(if where
66+
(intern (apply #'concatenate 'string
67+
(mapcar #'string things))
68+
(if (eq where t) *package* where))
69+
(make-symbol (apply #'concatenate 'string
70+
(mapcar #'string things)))))
71+
5872
(defmacro with-names ((&rest clauses) &body forms)
5973
"Bind a bunch of variables to fresh symbols with the same name
6074

0 commit comments

Comments
 (0)