Arc Forumnew | comments | leaders | submitlogin
1 point by thaddeus 5107 days ago | link | parent

In Clojure the core names from the core language are automatically imported into all/any namespaces(even the default one 'user'). So you don't have to use them, you can just do the same thing arc does -> (load-file "filename.clj").

And you can choose to incorporate name-spacing only when you need to.

That being said, once you start crafting projects having more than one file you will end up adding a bare min namespace, since it's just actually easier than load-file:

  i.e.
    (ns myprog.core) 
  does the same as: 
    (load-file "/myprog/core.arc")
  only it creates the names in the namespace 'myprog.core'.
Interactively at the REPL you can switch between namespaces,

  user=>(ns mynamespace)
  mynamespace=>
Or you can just load all your library files into a single namespace.

Since Clojure core libraries are already loaded, my example actually had to exclude the 'remove' causing a little bit of boilerplate:

  (ns arc.core
    (:refer-clojure :exclude [remove]))
but, you can easily stack the names of interest:

  .i.e  to add more items to exclude...

  (ns arc.core
    (:refer-clojure :exclude [remove find others]))
The same can be said if you want to selectively import:

  (ns myprog.core
   (:use [somelibrary.core :only (every re-sub pull]))
As opposed to loading everything from some extra library:

  (ns myprog.core
   (:use somelibrary.core))
In my mind it's really slick, and there's a plethora of options to manage them, should you need/want to.

> 'No need for a namespace declaration inside arc.core, or in the caller'.

None, but as stated above - you typically have one since it's easier.

[edit: None, assuming you choose to use load-file (load-file "arc/core.clj") which loads the code into the default namespace, or where ever you ran load-file)

I hope all that made sense.



1 point by akkartik 5107 days ago | link

"Since Clojure core libraries are already loaded, my example actually had to exclude the 'remove' causing a little bit of boilerplate."

I'm not too concerned about the verbosity when you need to exclude something. What clojure does seems fine.

I didn't realize that ns is like load, and not like PLT's module. It goes in the caller, not the callee. That's cool. But once I use:

  (ns arc.core) ; provides say find
Can I use all its declarations as just find and not arc.find?

If so that's pretty much what I want :)

-----

1 point by thaddeus 5107 days ago | link

> I didn't realize that ns is like load,

I'm not sure if Clojure is doing this for me or leiningen.

https://github.com/technomancy/leiningen

As I started right off using it.

[edit: yeah lein is doing the load for me, but you can still just use load if you like. To run as a script Clojure uses 'java -cp ....', so your files need to be on your classpath location. It's been a long time, since I bothered with that way.]

> Can I use all its declarations as just find and not arc.find?

Yup (well, find is actually taken by clojure core, so you need to exclude it if you wanted your own version, but for everything else, which I believe was the intent of your question, you're golden).

-----