This is a general symbol question in a specific context. The question I think I need to answer is: given a parameter containing a symbol 'foo, how do I manipulate the package part of the symbol so that it is eql to 'package:foo?
The more specific context: There is a unit-testing package, fiveam, that stores test functions in a hash table (it.bese.fiveam::*tests
) with keys like package::test-name
that hash to an object containing the tests. To run a test, one normally passes to the run!
function a symbol that is a hash key: (run! 'package::test-name
. If I'm calling run!
from the tests
package in which I defined the tests, I can just C-x C-e on (run! 'test-name)
. When calling from the SLIME REPL, I have to do (tests::run! 'tests::test-name)
, which is a mild inconvenience.
I'd like to run tests from cl-user with (run! 'test-name)
and omit the package name. I thought it would be simple to wrap run!
and add the missing package to the symbol, but all my tries fail, I guess in part because CL-USER:test-name
is a different thing from tests:test-name
.
The hash table in question uses eql
to test equality. In the tests
package:
(eql 'tests::foo 'foo) => T
In CL-USER:
(eql 'tests::foo 'foo) => nil
Various functions can return symbols (e.g. intern, make-symbol or format-symbol) but none of them are eql to the keys in the hash table:
(eql (alexandria:format-symbol t "foo::bar") 'foo::bar) => nil
(eql (make-symbol "foo::bar") 'foo::bar) => nil
Taking this out of the SLIME/REPL/FIVEAM context to generalize where I think the problem is, I can't figure out how to take 'bar
and turn it into 'foo:bar
as a symbol. I can specify it manually as 'foo:bar
, but I can't seem to get anything to eql 'foo:bar
, given 'bar
.
Note: I don't really care about typing the extra few letters for a package name. What I'm really trying to do here is improve my understanding of scoping and specifying symbols.
Thank you.
(find-symbol (symbol-name 'bar) :foo)
will return the symbol namedBAR
in the package namedFOO
if such a symbol is interned there. – jkiiski