I noticed pkg.clj in the clojure-contrib svn. I like it, and I'm
happy that you used my resource-loading code.
The one thing I'm not
sure about is (provide ...). I like the idea of being able load
packages from sources other than files (e.g. direct from svn/git/
http), but does every package need (provide ...)?
I can think of situations where a specialized variant of (require
'foo) would not actually be loading a file named foo.clj, but I can't
think of a situation in which (require 'foo) succeeds but 'foo is not
added to *packages*.
It's also possible that someone will mistakenly write (provide ...) at
the TOP of a source file, so that even if loading the entire file
fails, it still ends up on *packages* (Emacs undoes (provide ...) in
this case).
So my thought is: if (require 'foo) succeeds it should automatically
(provide 'foo). That way package writers don't have to do anything
special other than use the same names for files and namespaces. A
package may still (provide ..) additional packages if it wants to.
Let me know what you think.
I thought the same thing - I don't really understand provide.
Rich
It's also possible that someone will mistakenly write (provide ...) atthe TOP of a source file, so that even if loading the entire filefails, it still ends up on *packages* (Emacs undoes (provide ...) inthis case).
I'm not sure it needs to get more complex than that. Also requirecould ensure that no 2 requires for the same lib had different dirs,and thus could be used for versions:whizbangV2/wb-utilswhizbangV2/wb-sqlJust riffing here, not a real plan...
To continue riffing, here's one more idea:
(require-ns 'baz :in "foo/bar")
loads the file foo/bar/baz.clj and refers the 'baz namespace.
Also permits
(require-ns 'baz :in "/usr/local/lib/my-stuff")
for files that are not on the classpath.
N.B. We shouldn't be using the term "package" for Clojure stuff, Iavoided using it so we could always distinguish Java packages fromClojure namespaces.
Got it, that makes sense. Maybe we should just call them "libraries,"
avoiding the loaded term "module."
Yes! Now that I think about it, maybe :from would be a better name.This would be cool someday:(require 'best-library :from "svn://example.com/my-libraries/trunk")with appropriate caching, etc.If a namespace names is always a simple, unadorned symbol, it makessense that (require...) forms should use the same unadorned symbol.
They're alternative solutions to a problem. Right now they exist side
by side. Pkg violates the "avoid the word package when working with
Clojure" guideline from Rich so I'll likely withdraw it soon.
I've spent some time with "loader/require" today and I like it.
>> An argument to :from specifies a path to the implementation file's
>> parent directory. An absolute path (beginning with '/') specifies a
>> directory in the filesystem. A relative path specifies directories
>> relative to each of the classpath roots.
>
> Our non-Unix users (anyone?) might prefer File.isAbsolute() and
> File.pathSeparatorChar.
Good point, I had seen that "/" is a platform independent separator
for paths used by getSystemResource, but here I'm checking for an
absolute pathname. Is it even worth supporting an absolute ":from"
when "load-file" is available for that?
>> When :reload is true, the namespace will be reloaded if already
>> loaded.
>> When :reload-all is true, all directly and indirectly required
>> namespaces are also reloaded.
>
> This is a useful distinction.
>
> I'll look some more at this later, now I need to sleep. :)
Great! Thanks as always for your feedback and help.
--Steve