Fork me on GitHub
#beginners
<
2019-07-07
>
jayesh-bhoot06:07:38

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.

holyjak07: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.

jayesh-bhoot07:07:02

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

theeternalpulse07:07:29

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

jayesh-bhoot07:07:00

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

jayesh-bhoot07:07:58

But I understand now. @'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.

holyjak12: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.

jayesh-bhoot13:07:11

> 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).

jayesh-bhoot13:07:44

> 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!

theeternalpulse16:07:51

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

kurva09:07:07

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 ?

andfadeev09:07:24

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

kurva09:07:19

Thank you 🙂 now it is so obvious 🙂

kurva09:07:34

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

rpkn09:07:58

(thread/sleep 5000) is member access to a static method. (.sleep Thread 1000) is member access on an instance method. https://clojure.org/reference/java_interop#_member_access explains in greater detail.

jayesh-bhoot11:07:50

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

pez13:07:40

@jayesh-bhoot , 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.

jayesh-bhoot13:07:44

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

kurva19:07:10

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

haus20:07:29

How did you manually install the jars?

holyjak20:07:57

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

dorab21:07:17

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

dorab21:07:47

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.

thiru013022:07:40

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 (https://github.com/seancorfield/dot-clojure/blob/master/deps.edn). Is it possible to run the rebel and nrepl aliases together?

lilactown22:07:23

you can’t have multiple mains, unfortunately

thiru013022:07:43

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?

lilactown22:07:48

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

lilactown22:07:54

better to create your own main

thiru013022:07:56

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