Personally, I'd rather nobody use refer for anything except the
'clojure namespace itself. This would also be an argument against
:use. But my opinion seems to be in the minority, so I'll once again
drop it until I can find a new excuse for bringing it up again. :-)
> :refer (when you know another namespace is already present and you want to
> bring some or all of it into this namespace with filters)
Is there any reason not to use :use in this case? :use is more
robust, as it doesn't rely on your assumption that the namespace is
indeed already present. The only namespace I'm aware of that doesn't
behave properly with :use is 'clojure, since it's loaded from
clojure/boot.clj instead of clojure/clojure.clj.
> I like ":refer" over ":refer-clojure" because it's more general and
> shorter.
Well, it's not really shorter since you'd have to say ":refer clojure"
instead of ":refer-clojure". But it is more general, and therefore
requires less code to support more cases. If it's useful, I'm fine
with it.
The only other point I'll bring up is that it may be slightly less
surprising for a missing :refer-clojure to automatically refer
'clojure than it would be for the more general :refer to have a
special case for the refering of 'clojure if it's not mentioned.
> On the subject of shorter, the name "clojure/load" is already in use, but
> would be a better name for "load-resources" than "load-resources". I think
> we should consider changing the name of the former to something else like
> "load-reader" and using "load" for what is now load-resources (and :load for
> what is now :load-resources).
I have no objection to this.
--Chouser
Well, here's a patch for the behavior discussed on IRC. I'm posting
it only because it's complete and working, not in any attempt to
stifle further discussion. If we settle on any alternate solution,
this patch can just be ignored.
--Chouser
On Wed, Sep 3, 2008 at 4:36 PM, Stephen C. Gilardi <sque...@mac.com> wrote::refer (when you know another namespace is already present and you want tobring some or all of it into this namespace with filters)
Is there any reason not to use :use in this case? :use is more
robust, as it doesn't rely on your assumption that the namespace is
indeed already present. The only namespace I'm aware of that doesn't
behave properly with :use is 'clojure, since it's loaded from
clojure/boot.clj instead of clojure/clojure.clj.
I like ":refer" over ":refer-clojure" because it's more general and shorter.
Well, it's not really shorter since you'd have to say ":refer clojure" instead of ":refer-clojure".
But it is more general, and therefore requires less code to support more cases. If it's useful, I'm fine with it.
The only other point I'll bring up is that it may be slightly less
surprising for a missing :refer-clojure to automatically refer
'clojure than it would be for the more general :refer to have a
special case for the refering of 'clojure if it's not mentioned.
> Good point. It seems that :use would suffice except if both of the following
> are true for a particular namespace:
> - it's defined outside of a lib,
> - it's reasonable to want to refer to it.
>
> I'm not aware of any uses of namespaces that meet both of those criteria.
> Does anyone else know of any?
>
One thing I encountered with the new (ns) is when some Java code that
operates with Clojure creates a Namespace before the corresponding
.clj file is loaded. With the current behaviour, when the .clj loads
and calls (ns com.my-ns) it does not automatically refer 'clojure
since the namespace was already created by the Java code.
In this case a call to (clojure/refer 'clojure) was necessary.
Again we're talking about 'clojure, but its not inconceivable to me
that a similar situation could arise with a different namespace. A
manual call to clojure/refer is not a big deal to me, but being able
to contain this in a :refer clause in the call to (ns) would feel a
little cleaner.
Use of the general :refer clause would likely be low, but I don't see
any reason to limit flexibility for when its needed. I wouldn't expect
there be too much confusion between when to use :use and when to use
:refer--use :use if you want to load the lib if necessary and refer it
into the current namespace, and use :refer if you are sure that the
namespace is already loaded.
Rich might have something else to say about it though :).
/mike.
>
> On Wed, Sep 3, 2008 at 4:36 PM, Stephen C. Gilardi
> <sque...@mac.com> wrote:
>> I have been thinking recently that "(:refer ...)" would make a good
>> supported reference argument. Instead of "(:refer-clojure ...)", I
>> suggest
>> "(:refer ...)" which acts like any other call to refer but doesn't
>> require
>> its arguments to be quoted. "ns" would still refer to all of
>> clojure if
>> there is no explicit "(:refer clojure ...)" argument present.
>
> Personally, I'd rather nobody use refer for anything except the
> 'clojure namespace itself. This would also be an argument against
> :use. But my opinion seems to be in the minority, so I'll once again
> drop it until I can find a new excuse for bringing it up again. :-)
Was that conversation on the list? Just curious...
>
>> :refer (when you know another namespace is already present and you
>> want to
>> bring some or all of it into this namespace with filters)
>
> Is there any reason not to use :use in this case? :use is more
> robust, as it doesn't rely on your assumption that the namespace is
> indeed already present. The only namespace I'm aware of that doesn't
> behave properly with :use is 'clojure, since it's loaded from
> clojure/boot.clj instead of clojure/clojure.clj.
>
>> I like ":refer" over ":refer-clojure" because it's more general and
>> shorter.
>
> Well, it's not really shorter since you'd have to say ":refer clojure"
> instead of ":refer-clojure". But it is more general, and therefore
> requires less code to support more cases. If it's useful, I'm fine
> with it.
>
> The only other point I'll bring up is that it may be slightly less
> surprising for a missing :refer-clojure to automatically refer
> 'clojure than it would be for the more general :refer to have a
> special case for the refering of 'clojure if it's not mentioned.
Having both :use and :refer is unnecessary and will confuse newcomers
and there's no obvious benefit.
I'm in the :refer-clojure camp, with its absence bringing in all
symbols from clojure but with a simple way to turn it off. Perhaps
(:refer-clojure false) or using a special argument, such as :all, with
the :exclude filter.
>
>
>> On the subject of shorter, the name "clojure/load" is already in
>> use, but
>> would be a better name for "load-resources" than "load-resources".
>> I think
>> we should consider changing the name of the former to something
>> else like
>> "load-reader" and using "load" for what is now load-resources
>> (and :load for
>> what is now :load-resources).
>
> I have no objection to this.
Sounds good.
>
>
> --Chouser
>
> >
The other def's have no impact on the state except for the name
they're defining -- will defns also change *ns*? At the very least it
may cause other namespaces to be created (via :require for example).
The other def's, if repeated, fully replace the old definition with
the new one -- will defns do that, or will it just add any new
namespaces and aliases to any that already exist?
Maybe those are comments about the name more than the functionality.
Is there really any harm in re-refering 'clojure if ns (or defns) is
run a second time on the same namespace?
--Chouser
After sleeping on it, I think what we have been calling ns should be
called defns instead, and ns should just set *ns*. Thus there should
be only one defns for any particular namespace, and (ns foo) can be
used to set the namespace for a file and/or change the namespace at
the repl.
Thoughts?
this is my first post to the list (though I've been lurking for a
while) and I'm not yet actively working with Clojure, so take what I
say here with a grain of salt :).
So, if I understand this correctly, you'd have a file myns/myns.clj
containing (defns myns) along with :require and/or :use clauses for
the dependencies of the whole ns. Other files under myns/ would
contain just the statement (ns myns).
Personally, from a separations-of-concerns standpoint, I'd prefer if
every file were responsible for getting access to all the libs it needs.
Oh, one (tiny) niggle wrt the name "defns": it looks a bit like the
plural form of "defn", so it might be confused with defmulti or
something that defines a bunch of functions at once.
just my 2¢,
--Chris
I didn't think about the plural angle - anyone else bothered by that?
The alternative is defnamespace.
On Sep 5, 2008, at 3:23 PM, Rich Hickey wrote:I didn't think about the plural angle - anyone else bothered by that?The alternative is defnamespace.
Erg. Here, I think shorter is better. Maybe it's only once per file,
but you still have to type it every time you start a new file. If
people don't like the similarity to defn, then maybe just call it
"namespace". But every other namespace-related function uses "ns."
By the way, what happened to "in-ns"? Couldn't that be the form used
for switching to a namespace that already exists?
On Sep 3, 5:14 pm, Chouser <chou...@gmail.com> wrote:On Wed, Sep 3, 2008 at 4:36 PM, Stephen C. Gilardi <squee...@mac.com> wrote:I saw some discussion of how to fix this on the IRC log but I can't get onat the moment.It looks like the current plan is to change "ns" to remove the sensitivityto "the namespace is already defined" and add "(:refer-clojure ...)" to thelist of supported reference arguments.Well, here's a patch for the behavior discussed on IRC. I'm postingit only because it's complete and working, not in any attempt tostifle further discussion. If we settle on any alternate solution,this patch can just be ignored.
I've applied this patch (SVN rev 1017).
Also you mentioned in IRC (but not here I think) that ns and in-ns
have special resolution rules, so that you never have to say
clojure/ns or clojure/in-ns:
user=> (in-ns 'foo)
#<Namespace: foo>
foo=> (prn "hi")
java.lang.Exception: Unable to resolve symbol: prn in this context
foo=> (in-ns 'user) ; <-- but this works fine
#<Namespace: user>
user=>
I've updated zip-filter and mmap in clojure.contrib to use the new
format. I like it. It's such a relief to be able to rely on the
availability of lib.clj goodness, and the ns macro is a very pleasant
way to use it.
--Chouser
>>> On the subject of shorter, the name "clojure/load" is already in
>>> use, but
>>> would be a better name for "load-resources" than "load-resources".
>>> I think
>>> we should consider changing the name of the former to something
>>> else like
>>> "load-reader" and using "load" for what is now load-resources
>>> (and :load for
>>> what is now :load-resources).
>>
>> I have no objection to this.
>>
>
> Me neither, other than the breakage for people using load, most of
> whom I presume are loading from strings to do evals, and may be
> placated with a load-string.
I've enclosed a patch to implement this.
Changes:
renamed clojure/load to clojure/load-reader
added clojure/load-string
renamed clojure/load-resources to clojure/load
fixed up doc strings accordingly
These changes are all at the Clojure level--the load method of
Compiler is not changed.
$ cd <clojure-root-dir>
$ patch -p0 < load-reader.patch
patching file src/clj/clojure/boot.clj
$
--Steve