namespace names containing '/' ?

8 views
Skip to first unread message

jon

unread,
Feb 29, 2008, 12:37:08 PM2/29/08
to Clojure
Hi,
(using release 20080213)
If namespaces are not hierarchical, ie. you can only use a single '/'
in a qualified symbol.. then shouldn't '/' be disallowed from the
namespace name?
eg.

user=> (in-ns 'aaa/bbb)
#<Namespace: aaa/bbb>
aaa/bbb=> (def ccc 1)
#<Var: aaa/bbb/ccc>
aaa/bbb=> ccc
1
aaa/bbb=> aaa/bbb/ccc
java.lang.Exception: ReaderError:(7,1) Invalid token: aaa/bbb/ccc
at clojure.lang.LispReader.read(LispReader.java:146)
at clojure.lang.Repl.main(Repl.java:60)
Caused by: java.lang.Exception: Invalid token: aaa/bbb/ccc
at clojure.lang.LispReader.interpretToken(LispReader.java:212)
at clojure.lang.LispReader.read(LispReader.java:138)
... 1 more

Thanks, Jon

jon

unread,
Mar 5, 2008, 6:24:15 AM3/5/08
to Clojure
Hi, I'm still curious what the current "official guidelines" & future
clojure plans are regarding:
* namespace names containing '/'
and the related issue of
* symbols containing '.' (which can be defined, but not used without
being qualified because of the clash with java class names. see
below.)

- Should both of these simply be avoided everywhere?
- Are hierarchical namespaces of any practical value?
- Might they come in a future release?
- If in java, namespaces are arranged like "javax.security.auth",
"javax.sound.midi", should clojure coders be emulating something like
that with a namespace naming scheme like "mystuff--security--auth",
"mystuff--sound--midi", or is using '.' as separator safe for this
usage?

Thanks, Jon

-------------------------------------
user=> (in-ns 'ccc.ddd.eee)
#<Namespace: ccc.ddd.eee>
ccc.ddd.eee=> (clojure/refer 'clojure)
nil
ccc.ddd.eee=> (def fff.ggg 2)
#<Var: ccc.ddd.eee/fff.ggg>
ccc.ddd.eee=> fff.ggg
java.lang.ClassNotFoundException: fff.ggg
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
...
ccc.ddd.eee=> ccc.ddd.eee/fff.ggg
2
-------------------------------------

Rich Hickey

unread,
Mar 5, 2008, 11:13:54 AM3/5/08
to Clojure


On Mar 5, 6:24 am, jon <superuser...@googlemail.com> wrote:
> Hi, I'm still curious what the current "official guidelines" & future
> clojure plans are regarding:
> * namespace names containing '/'
> and the related issue of
> * symbols containing '.' (which can be defined, but not used without
> being qualified because of the clash with java class names. see
> below.)
>
> - Should both of these simply be avoided everywhere?

Yes.

> - Are hierarchical namespaces of any practical value?

Could be, but most of the time it's just a convention for the
formatting of the prefix part of a 2-part identifier. Java goes
further to consider the parts to have relationships to the file system
hierarchy - not everyone likes that.

> - Might they come in a future release?

Probably not formally.

> - If in java, namespaces are arranged like "javax.security.auth",
> "javax.sound.midi", should clojure coders be emulating something like
> that with a namespace naming scheme like "mystuff--security--auth",
> "mystuff--sound--midi", or is using '.' as separator safe for this
> usage?
>

Don't use '.' or '/'. You can just say dash. e.g. org-my-ns, if you
like.

I expect to add ns aliases at some point, to make long namespace names
viable.

As the reader docs say, "Symbols begin with a non-numeric character
and can contain alphanumeric characters and *, +, !, -, _, and ?", and
clearly state the special interpretation of '.' and '/'. I would stick
to that. Note (as you have) that not everything that is disallowed is
enforced at this time. It's worth following the rules even if you are
not getting caught :)

Rich
Reply all
Reply to author
Forward
0 new messages