This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-12-21
Channels
- # adventofcode (82)
- # bangalore-clj (1)
- # beginners (44)
- # boot (7)
- # boot-dev (25)
- # cider (1)
- # cljs-dev (3)
- # cljsrn (14)
- # clojars (11)
- # clojure (210)
- # clojure-dusseldorf (4)
- # clojure-gamedev (2)
- # clojure-greece (11)
- # clojure-italy (6)
- # clojure-norway (6)
- # clojure-russia (6)
- # clojure-serbia (2)
- # clojure-spec (43)
- # clojure-sweden (1)
- # clojure-uk (77)
- # clojurescript (43)
- # cursive (1)
- # data-science (3)
- # datomic (32)
- # duct (3)
- # figwheel (2)
- # fulcro (71)
- # graphql (3)
- # hoplon (14)
- # jobs-discuss (3)
- # lambdaisland (1)
- # leiningen (2)
- # luminus (2)
- # lumo (14)
- # off-topic (16)
- # om-next (1)
- # perun (5)
- # random (1)
- # re-frame (19)
- # reagent (37)
- # ring-swagger (3)
- # shadow-cljs (157)
- # specter (6)
- # sql (29)
- # unrepl (14)
Hi, when compiling a ring project into a jar, is there a difference that I should know between using lein ring uberjar
and lein uberjar
?
I've always blindly using lein ring uberjar
as the tutorial suggested, and I notice when I run the jar produced by lein uberjar
it starts a repl session instead of running a web server like lein ring uberjar
does.
with lein uberjar you must configure the main ns to be launched when the jar is run
if that config is missing, you get clojure.main as a default, clojure.main is a repl
you can still run an app with that jar java -cp my-uber.jar clojure.main -m my.ns
will launch my.ns/-main
but you can also config leinengen so that ns of your choosing runs when someone runs the jar
That's a very concise explanation @noisesmith, thank you
I have an Atom with a list like so
'((1 2)(2 3)(3 4))
And I need to append an item to the front and drop the last one of. Can I do that in one swap!
?If I want to keep to the functional pardigem as much as possible, i should not let my functions operate on the global state?
is there documentation on when/why (gimme-a-fn (fn [x] (some-thing x)))
works where (gimme-a-fn #(some-thing %))
doesn't?
@slack1478 Can you give a bit more context of where the #( .. )
form doesn't work?
All three of (gimme-a-fn (fn [x] (some-thing x)))
, (gimme-a-fn #(some-thing %))
, and (gimme-a-fn some-thing)
should be identical in behavior...
@seancorfield https://github.com/jedahan/metapng/blob/master/src/metapng/core.clj#L13-L24 that map
Ah, because the function is creating a vector literal.
#([(keyword (.getKey %)) (.getVal %)])
would try to "call" the vector since it's in the first position.
You could use #(vector (keyword (.getKey %)) (.getVal %))
(and, no, you can't quote it -- you want the contents to be evaluated)
thanks @seancorfield
(vector a b c)
vs (vec coll)
Why changing global variable using just def
is discouraged and using atom
is considered better than that?
I’d say thread-safety mostly. But conceptually, def
is for defining immutable values. There’s ways around that, but if you use them you’re kind of fighting against the language.
But the same applies to single-threaded programs. People just go and use atom
or volatile
.
It seems like an language convention indeed.
Yeah, "convention" sounds like a good way to put it. I'd even call it a best practice, in the sense of "you're better off using an atom you don't need than needing one you don't use."
Thank you, @manutter51!
@ghsgd2 volatiles are never a good choice to replace a var
they are unsafe to use from more than one thread, they are only good for local bindings
What @noisesmith said. Consider them effectively private API for the purposes of this room
Thank you, @noisesmith, @ghadi!
@ghsgd2 Also, a Var (from a def
) is a very particular thing with its own special behaviors, different from an atom:
boot.user=> (def a 42)
#'boot.user/a
boot.user=> a
42
boot.user=> #'a
#'boot.user/a
boot.user=> (type #'a)
clojure.lang.Var
boot.user=> (ancestors *1)
#{clojure.lang.IFn java.lang.Runnable java.io.Serializable clojure.lang.IDeref clojure.lang.IRef clojure.lang.AReference java.util.concurrent.Callable clojure.lang.Settable clojure.lang.ARef java.lang.Object clojure.lang.IMeta clojure.lang.IReference}
boot.user=> (def b (atom 42))
#'boot.user/b
boot.user=> (type b)
clojure.lang.Atom
boot.user=> (ancestors *1)
#{clojure.lang.IDeref clojure.lang.IRef clojure.lang.AReference clojure.lang.IAtom2 clojure.lang.IAtom clojure.lang.ARef java.lang.Object clojure.lang.IMeta clojure.lang.IReference}
In particular, if you def
something else to a
, it gets a
's value at that point whereas if you def
something else to b
, you'll get the indirection:
boot.user=> (def c a)
#'boot.user/c
boot.user=> (def a 13)
#'boot.user/a
boot.user=> c
42
boot.user=> (def d b)
#'boot.user/d
boot.user=> (reset! b 13)
13
boot.user=> d
#object[clojure.lang.Atom 0x46bd848a {:status :ready, :val 13}]
boot.user=> @d
13
boot.user=>
Thank you, @seancorfield! Indirection stuff is interesting.
Hi, I want to play around and build an mobile app/game with clojurescript. The most popular way seems to be with re-natal. Do you know of any good tutorials or similar? I've been using clojure(script) for about two months now and I really like it. Want to do everything with it now! But I'm new to react and everything, so not sure where to start. Which one of on.next/reagent/rum is easiest to start with? I'm leaning towards reagent, but rum looks cool too. I want it to be as simple as possible. Thanks in advance!