This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
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.
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.
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).
> 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]))
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.
https://clojure.org/reference/java_interop#_member_access explains in greater detail.
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.
how to set up lein
to look up in my local .m2
I have some jars manually installed, but it does not see
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
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 (https://github.com/seancorfield/dot-clojure/blob/master/deps.edn). Is it possible to run the rebel and nrepl aliases together?
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
hmm.. ok. This is the only thing I miss in tools.deps... thanks for the suggestions @lilactown