This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-03-01
Channels
- # announcements (4)
- # aws (1)
- # beginners (172)
- # cider (16)
- # cljdoc (63)
- # cljsrn (7)
- # clojure (150)
- # clojure-dev (8)
- # clojure-europe (26)
- # clojure-gamedev (6)
- # clojure-greece (23)
- # clojure-nl (4)
- # clojure-spec (10)
- # clojure-uk (101)
- # clojurescript (40)
- # community-development (5)
- # cursive (19)
- # datomic (54)
- # emacs (39)
- # figwheel-main (5)
- # fulcro (4)
- # graphql (16)
- # immutant (5)
- # jobs (8)
- # jobs-rus (1)
- # leiningen (1)
- # off-topic (31)
- # planck (1)
- # re-frame (7)
- # reagent (8)
- # reitit (6)
- # remote-jobs (4)
- # shadow-cljs (11)
- # spacemacs (18)
- # specter (2)
- # sql (58)
- # vim (2)
- # yada (5)
How should this -Dclojure.server.repl="{:port 5555 :accept clojure.core.server/repl}"
look like when passed to :jvm-opts
?
unfortunately there are some issues with handling this due to the various layers of spaces/escaping/quoting
the trick is to replace the spaces with commas (as commas are whitespace to Clojure, but not to bash)
so more like :jvm-opts ["-Dclojure.server.repl={:port,5555,:accept,clojure.core.server/repl}"]
I believe
eventually this will be fixed, but it's kind of a nightmare
sorry it's super weird :)
it's double weird because of how it goes from command-line, to Clojure, to a file, back to bash, and then into a java command line at the end :)
@lockdown- If you're looking for "inspiration" with deps.edn
, I'll point you to my .clojure
file https://github.com/seancorfield/dot-clojure
It has several comma-is-whitespace things in there 🙂
@seancorfield handy, already seeing some needed stuff, thx
There are a bunch of free ones. https://www.braveclojure.com is one that’s frequently mentioned
I figured out a way to do it, but I’d like to know what a good way is to do it efficiently 🙂
user=> (into {} (keep (fn [x] (when (pos? x) [x (inc x)]))) [1 2 -2 3])
{1 2, 2 3, 3 4}
what does keep do?
@lady3janepl the version with into + keep as transducer is both faster (into internally uses transients, and fast reductions of coll rather than converting to seq) and more efficient (doesn't allocate unnecessary objects)
clojure.core/keep
([f] [f coll])
Returns a lazy sequence of the non-nil results of (f item). Note,
this means false return values will be included. f must be free of
side-effects. Returns a transducer when no collection is provided.
in this case, I want to return a result if one of t1, t2 or t3, AND keywords, are not nil
you could use spectre perhaps
@lady3janepl how about lifting the the or
into when-some
(I might just create another lookup map, but for the sake of example, if I was looking in a sequence of [ x1, x2, x3 … ] for the first element where (f x) returns true)
any way I can test the equality of anonymous functions without relying on the instance of the function itself?
I have something like this:
(= {:name "simple-pipeline", :steps [{:name "log1", :func #object[ns.pipeline_test$first_func 0x8d8f754 "ns.pipeline_test$first_func@8d8f754"]} {:name "log2", :func #object[ns.pipeline_test$second_func 0x25673087 "ns.pipeline_test$second_func@25673087"]}]} {:name "simple-pipeline", :steps [{:name "log1", :func first-func} {:name "log2", :func second-func}]})))
functions have reference equality. if they are anonymous they most likely won't be the same even if they are the "same"
I see @dpsutton, even though I would do something like this?
(def first-func (fn [log] (log "Hello")))
(def second-func (fn [log] (log "World")))
(pipeline/defpipeline simple-pipeline
"log1" first-func
"log2" second-func)
(def simple-pipeline-output
{:name "simple-pipeline"
:steps [{:name "log1"
:func first-func}
{:name "log2"
:func second-func}]})
in fact, I think something is wrong with my macro I'm writing, as the first has :func #object[yadda.yadda]
while the second has :func first-func
@victorbjelkholm429 yes, first-func and second-func are different objects.
@borkdude no, that I understand. But I explicitly define first-func
outside to be used in both. The function equality is something I'm only interested in the tests, not the in the running system
so, what I'm unsure about, is why one gets a reference while the other is just the symbols. Here is the full scope of what I'm doing https://gist.github.com/victorb/e7622a90db51abc19fe7f602ac6d4d4a
most probably I'm screwing up something with the macro, as it's my second macro I try to write...
I use potpuri.core https://cljdoc.org/d/metosin/potpuri/0.5.1/api/potpuri.core#map-vals
hi, I am trying to get working server reloading with yada and mount whenever code changes. Not sure whether there is some yada specific solution, but as I understand mount (and similar libraries) should have support for this:
(defn create-server []
(yada/listener
["/"
[["" (yada/as-resource "Root")]
["hello" (yada/as-resource "Goodbye World!")]
["test" (yada/resource {:produces "text/plain"
:response "This is a test!"})]
[true (yada/as-resource nil)]]]
{:port port}))
(mount/defstate
server
:start (create-server)
:stop ((:close server)))
maybe I am doing something wrong, here is the rest of the setup, based on Luminus template:
(defn stop-app []
(doseq [component (:stopped (m/stop))]
(log/info component "stopped"))
(shutdown-agents))
(defn start-app [args]
(doseq [component (-> args
(cli/parse-opts cli-options)
m/start-with-args
:started)]
(log/info component "started"))
(.addShutdownHook (Runtime/getRuntime) (Thread. stop-app)))
(defn -main [& args]
(start-app args))
basically when I change create-server, I would like to have everything automatically reloaded
so you want to hook up mount/start and mount/start with a file system watching thing?
ya, I want whenever source code file is updated, we run mount/start (only on those which have :reloading turned on, so for instance not on db connection)
and how do you hook it up to watching file system?
so I can just press a hotkey to send code to my REPL to be evaluated (like a whole namespace)
hmm, that would work
is it advantageous to not reload it automatically? I am quite used for the figwheel setup on the client, but not sure whether it works equally well on the server
I like both. in CLJS, hot reloading is easier because you often have to restart your whole system in order to see your changes
when I'm doing work that doesn't need that entire-system-restart to get feedback, like working on some data transformations, business logic, etc., I like just sending stuff to my REPL
you can get the same general thing with either solution. I prefer the REPL more for the amount of control I get, e.g. I can just re-define one function or var, instead of the whole file
I see, is there some mount function to reload everything?
for autoreloading, I could try to adapt https://github.com/ring-clojure/ring/blob/95e4ca25d5b98c45f927b32b5c3c85c21c999d96/ring-devel/src/ring/middleware/reload.clj
But that will reload all resources, even those which with :on-reload :nope
what is this apostrophe means in here https://github.com/clojure/core.cache#example-usage after C1 (`C1'`) ?
if you re-define a defstate
that is depended on by other defstate
s, it should reload all of the ones in the dependency chain
math people do that all the time. they'll have a variable called x
, and then a variable that is derived from it will be x'
, x''
, etc.
@masta it's a naming convention, not a syntax, and it x' indicates "a slight variation on the thing with the name x"
like in math
I see, thx lilactown for the info, I think I will start with what you suggest and maybe rework the setup later as I understand everything much better
I want to do something like
(-> validation-map
(update :valid? and (apply-rule rule data)))
Do you usually clean up the var-quotes (`#'`) when releasing the software? I found var-quote a convenient way to try things quickly without reloading everything. For example:
(defn foo [name] (str "foo" name))
(def bar-1 (partial foo "1"))
(def bar-2 (partial #'foo "2"))
In this case, when I changed foo
, I can evaluate foo
itself and calling bar-2
would see the change.
The only reason I'm using var-quotes is for development, so I'm wondering if it's a nice thing to clean them up afterwards.And a followup question is: what's the use cases for var-quotes other than development?
consider the use of a REPL into production: the line between dev and prod is blurred 😛
Sure, thanks @borkdude
the runtime overhead of using a var rather than a function in a first-class context isn't different from using something by name inside a normal function body, so you might find it ugly but it's not a behavior or performance problem
Would you prefer writing a function like below instead?
(defn bar-1 [] (foo "1"))
Or it doesn't matter
Sorry I'm still trying to understand how to use the repl effectively
Yeah that looks nicer
Would you help me understand why (def bar-1 #(foo "1")) doesn't need to be re-evaluated with foo changes?
Does all the #()
forms invoke the symbols inside via their vars?
@dawranliou the body of that function compiles to byte-code that looks up foo on each call
all expressions do that, it doesn’t have to be within a function. e.g. when I eval foo
in the REPL, the var is also “consulted”
the symbol foo
is resolved to a var and then the value associated with that var is returned
the distinction I was making was (fn [] (foo x)) and (partial foo x) - partial doesn't create bytecode that looks up foo, it gets passed only the value
both create functions, only one is able to do that lookup
@dawranliou https://stackoverflow.com/questions/9113387/difference-between-symbols-and-vars-in-clojure
Thanks the conversation is very helpful. I had some misconception about vars and symbols.
Note that you can pass a Var to partial
:
user=> (defn foo [a b] (+ a b))
#'user/foo
user=> (def foo-2 (partial #'foo 2))
#'user/foo-2
user=> (foo-2 3)
5
user=> (defn foo [a b] (* a b))
#'user/foo
user=> (foo-2 3)
6
user=>
Hah! That'll teach me to scroll further back before diving in! 🙂
same issue applies to fnil, comp, juxt, complement, etc.
I feel like @noisesmith’s list consists of many high-order functions. Does most high-order functions have this behavior?
the ones that return a function
it's caused by the evaluation strategy of clojure - the symbol is resolved from a var to a value before being passed to the function, so it can't capture the var
unless the var itself is explicitly what you pass
Am I understand it correctly: The symbols inside the fn form is only evaluated when the fn is called.
so the function partial, is passed the value that the symbol is resolved to, not the symbol
Phew that’s a big TIL for me