On 30/10/13 16:56, P Martin wrote:
Thanks - I'm still a little confused on the different between use and require.

'use' is sort of deprecated after it was noticed that people were abusing it. It's not exactly deprecated because in some cases like incremental development at the repl it is really usefyl to have. That said, 'require' can do everything 'use' can via " :refer :all". so what I'm saying is the the following two are equivalent :

(require '[clojure.tools.macro :refer :all])
(use '[clojure.tools.macro])

Now, in perhaps 8/10 cases you should not do any of that. The next guy that will look at your code will not have the slightest clue what external fns you're using. He literally has to manually inspect the entirity of that external namespace and figure out which ones you've actually used. A more informative way would be the following 2:

(require '[clojure.tools.macro :as mac]) ;;if you're unsure of what you 'll end up using just alias it (require '[clojure.tools.macro :refer [name-with-attributes mexpand-all ]]) ;;if you know upfront what you need, specify it

using the second you don't need an alias, but you've explicitly said "here are the only vars i've used". Massive difference don't you agree?

In the case of var-clash due to same name, just make sure you use aliases. That is if you want both vars with the same name. If you don't just overwrite the one or :exclude it via:

(:refer-clojure :exclude [==])   ;;core.logic does this all the time

When I try your suggestion for the matrix library, (require '(clojure.core.matrix :as mat)), I get:

IllegalArgumentException Don't know how to create ISeq from: clojure.lang.Keyword clojure.lang.RT.seqFrom (RT.java:505)


I'm really sorry about that...I'm pretty sure that works in a ns-declaration, I'm puzzled as to why it doesn't work here. In any case, a quoted vector (as shown above) does work just fine. It also looks nicer :)

hope that helps,

Jim

--
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- You received this message because you are subscribed to the Google Groups "Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to