Hi all,
why does the existance of a namespace not suffice to use or require it?
Currently, with clojure 1.3, it has to be associated with a class or
clojure file.
Here's a simple example REPL session:
--8<---------------cut here---------------start------------->8---
user> (ns test)
nil
test> (defn foo [x] (+ 2 x))
#'test/foo
test> (in-ns 'user)
#<Namespace user>
user> (test/foo 2)
4
user> (find-ns 'test) ;; finding works
#<Namespace test>
user> (use 'test) ;; using doesn't work
Could not locate test__init.class or test.clj on classpath:
[Thrown class java.io.FileNotFoundException]
; Evaluation aborted
user> (require '[test :as t]) ;; neither does requiring
Could not locate test__init.class or test.clj on classpath:
[Thrown class java.io.FileNotFoundException]
; Evaluation aborted
user> (refer 'test) ;; referring does work
nil
user> (foo 2)
4
--8<---------------cut here---------------end--------------->8---
So while I can't use or require it, I can refer it. However, what I
really want to do is to require it with some short alias.
Unfortunately, refer doesn't support an :as option.
Why I think I need that: I'm playing around with core.logic, and there I
generate relations (defrel, which in the end defines a Var with def)
from some spec I get at runtime. In order not to clutter *ns*, I do
that in some new namespace by generating some do-form with ns and tons
of defrels, and then evaling that.
After the relations are there, I want to populate them with facts.
Since there can be many fact bases for the relations, I use another
namespace. In that, I want to easily access the relations using some
prefix, as (require 'foo :as 'f) would allow. I can't really refer that
namespace, because it's highly likely that some relation names clash
with clojure.core defs.
For the time being, I've changed my code a bit to prefix all relations
with a +, but artificial prefixing is just not right if you have
namespaces...
Bye,
Tassilo
--
(What the world needs (I think) is not
(a Lisp (with fewer parentheses))
but (an English (with more.)))
Brian Hayes, http://tinyurl.com/3y9l2kf
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en