Fork me on GitHub

Hi. I am trying to get my head around symbols, and its relation to Var. Is my following understanding correct? With (def xyz 1), a Var with value 1 is assigned, and the symbol xyz refers to that Var.

👍 4
Jakub Holý (HolyJak)07:07:03

Symbol is a syntax construct just like "a string". One of its possible uses is, as you point out, to serve as names for vars.


Ok. So (def xyz 1) does not create a Var named xyz, but a symbol named xyz. correct?


if you do (var? xyz) you will get false, but (var? (resolve xyz)) you get true


Great. I didn't know about var?. A correction: (var? (resolve 'xyz)) gets me true.


But I understand now. @U0522TWDA's explanation of symbol as 'a string' that can refer to anything helps a lot! Also, in the meantime, I discovered symbol? resolve deref and class. These are great utility functions.

Jakub Holý (HolyJak)12:07:10

No, def does not create a symbol,symbol just is, such as a string or a number. It creates a var and adds a mapping from the symbol to the var. (you could have multiple symbols being mapped to the same var.


> symbol just is, such as a string or a number Ok. So symbol is one of the literals in clojure. Re-reading the official clojure tutorial, it says the same thing (symbols are literals).

👍 4

> It creates a var and adds a mapping from the symbol to the var. (you could have multiple symbols being mapped to the same var. This makes the concepts much clearer!


If you travel back in lisp time they use symbols pretty much in place of keys and many times strings.


Why this:

(def dothreads!
  [f & {thread-count :threads
        exec-count :times
        :or {thread-count 1 exec-count 1}}]
  (dotimes [t thread-count]
    (.submit thread-pool
             #(dotimes [_ exec-count] (f)))))
gives me too many arguments to def ?


Def is for defining global var, defn is for function definition, it is like (def f (fn [arg]))


Thank you 🙂 now it is so obvious 🙂

👍 4

why this one works:

(Thread/sleep 5000)
and this one does not:
(.sleep Thread 1000)
in REPL..? It giver weird IllegalArgumentException No matching method found: sleep for class java.lang.Class clojure.lang.Reflector.invokeMatchingMethod


(thread/sleep 5000) is member access to a static method. (.sleep Thread 1000) is member access on an instance method. explains in greater detail.

👍 4

Can anyone recommend which vscode extensions to use for clojure dev?


@jysh , I publish Calva, intending it to provide an easy to start with and easy to use Clojure dev environment. I also try to be an active maintainer, and thus feel I can recommend it without blushing. Welcome to #calva-dev for questions about it.

calva 4

Thank you @pez. While waiting for responses, I chose Calva as well.

calva 4

how to set up lein to look up in my local .m2 I have some jars manually installed, but it does not see


How did you manually install the jars?

☝️ 4
Jakub Holý (HolyJak)20:07:57

Perhaps ask in #leiningen ? Perhaps the answer is here: > Based on the documentation, it looks like the key you're after is :local-repo in project.clj


Not sure what you're specifically asking for, but...


If you have two projects, say aaa and bbb and you want to use aaa in bbb, you can go into aaa and do lein install. That should put the aaa.jar into your local ~/.m2 and make it available for use in bbb.


With tools.deps is it possible to leverage multiple aliases that run code (i.e. not necessarily via main-opts). E.g. I'm looking at Searn Corfields deps.edn file ( Is it possible to run the rebel and nrepl aliases together?


you can’t have multiple mains, unfortunately


damn.. ya that's what I want I guess. But is there no other way to run arbitrary code in an alias without main-opts?


I think you can invoke clojure.main and then execute a bunch of clojure code but it’s…. gross


better to create your own main


hmm.. ok. This is the only thing I miss in tools.deps... thanks for the suggestions @lilactown