This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-03-23
Channels
- # beginners (63)
- # cljs-dev (1)
- # cljsjs (1)
- # cljsrn (11)
- # clojure (208)
- # clojure-berlin (2)
- # clojure-dusseldorf (5)
- # clojure-italy (5)
- # clojure-norway (56)
- # clojure-russia (7)
- # clojure-spec (85)
- # clojure-uk (27)
- # clojurescript (191)
- # core-async (73)
- # cursive (4)
- # datomic (62)
- # defnpodcast (1)
- # hoplon (2)
- # jobs-rus (1)
- # juxt (14)
- # keechma (1)
- # leiningen (1)
- # lumo (126)
- # off-topic (2)
- # om (11)
- # onyx (27)
- # pedestal (52)
- # planck (21)
- # powderkeg (1)
- # re-frame (32)
- # reagent (14)
- # ring-swagger (1)
- # rum (3)
- # slack-help (19)
- # specter (23)
- # untangled (32)
- # vim (7)
- # yada (43)
Why would one use a var quote instead of the symbol? As example, @yogthos uses the var quote for home-routes in the luminus template. Why not use the unquoted symbol? https://github.com/luminus-framework/luminus-template/blob/master/resources/leiningen/new/luminus/core/src/handler.clj#L38
stuartrexking a symbol is a function that looks itself up in an associative data structure
it has nothing to do with the function of the same name (unless you use it to look up a function in a namespace via resolve)
oh - unquoted symbol
@stuartrexking every time you call a var, it looks up its definition to call it
when you pass a function by name, it is only looked up once (when it gets passed in) and the recipient gets that specific value closed over
if you change the definition, the closure doesn't see it, and still uses the old version
And by change definition you mean rebind?
I mean using def or defn again
so, using the var-quote form allows changing the definition on the fly without having to restart the server process using it
Ok, I understand.
this is incompatible with using clojure.tools.namespace/refresh
With routes, it’s nice to use #‘sym
so that while you’re developing in the REPL, you can redefine sym
and the new version is picked up automatically.
Ok, I see.
refresh destroys the old var (or at least thinks it does) - but you hold onto it - which means def changes a new var and not the one you are using
so don't use var-quote for a server, and clojure.tools.namespace/refresh, in the same project
Ok, thanks @noisesmith, @seancorfield
@stuartrexking I think the specific use case for #'home-routes
is that you want to "wrap" just these routes with wrap-csrf
and wrap-formats
without wrapping also oauth-routes
and service-routes
.
Yes. What I wanted to know was why use the var-quoted #'home-routes rather than just home-routes
All good now. I understand the difference.
You can still wrap with unquoted symbol.
@yogthos explains it in "Web development with Clojure, 2nd edition" on page 35:
The macro makes sure that the route is resolved before the middleware is applied. This ensures that middleware is only applied to specific routes, instead of being run globally for all routes.
You just can't redefine it.
no, there's a diffrence - using #'home-routes
ensures that middleware is applied only to home-routes
and not to the other routes
jumar var quoting has nothing to do with that separation of middlewares though
well, my understanding is that you need to use #'home-routes
instead of plain home-routes
to achieve that - but I might be wrong
you are - the difference is that the var quote sees later redefinitions when used as a first class argument - it's not about the middleware wrapping per se
function calls inside another defn are looked up when used, but functions passed as args are captured, the var quote overrides the capture and allows a fresh lookup
@noisesmith thanks for clarification. This is indeed described on p. 31 in Web Development with Clojure
I'm trying to iterate through a ByteBuffer with map-indexed
or doseq
but I get
Caused by: java.lang.IllegalArgumentException: Don't know how to create ISeq from: java.nio.HeapByteBuffer
dumb question—do I have to restart the REPL every time I edit a clj file? Or does the REPL autoload my clojure files when edited?
@camdenclark if you're using Cursive just right-click then Load file to REPL
(for reference, I’m using vim fireplace with vim and my repl is hooked in)
hm, maybe I should bite the bullet and learn cursive
ooh! I figured it out!
@camdenclark in general you start repl once, and then only sync changed files, loading them
sometimes you should restart repl, for ex if you have new dependency in project.clj, but in some editors (ex. emacs) you can hotload deps as well
that’s not emacs though, that’s pomegranate - you don’t even need an editor to do it
yeah I think I can hotload deps too with this
b5
(defn get-values [byte-buffer]
(let [inner
(fn f [byte-buffer limit pos]
(when-not (= limit pos)
(cons (.get byte-buffer) (lazy-seq (f byte-buffer limit (inc pos))))))]
(inner byte-buffer (.limit byte-buffer) 0)))
why not just use (map f (.array buf)) ?
or more specifically
(map f (java.util.Arrays/copyOf (.array bb) (.limit bb)))
I actually think the first version might be better - I thought .limit reflected what had been put in the buffer rather than the size of the underlying array, but it’s the latter, so it’s redundant
Is it possible to call a macro from within a macro while preserving the literal arguments and then continue using the result before returning from the enveloping macro? For example, wrapping clojure.spec/keys
with a macro that calls it and uses the spec object before returning another.
you can generate code that uses the returned object
user=> (defmacro a [n] `(+ 1 ~n))
#'user/a
user=> (a 1)
2
user=> (macroexpand-1 `(a 1))
(clojure.core/+ 1 1)
user=> (defmacro b [n] `(+ 1 (a ~n)))
#'user/b
user=> (b 1)
3
user=> (macroexpand-1 `(b 1))
(clojure.core/+ 1 (user/a 1))
I don't understand the 'preserving literal arguments' part of the question.
It means that calling (b (some expression))
will pass that expression as is to macro a
.
You can pass quoted forms.
user=> (defmacro q [arg] `(quote ~arg))
#'user/q
user=> (q `(+ 2 2))
(clojure.core/seq
(clojure.core/concat
(clojure.core/list (quote clojure.core/+))
(clojure.core/list 2)
(clojure.core/list 2)))
Does it help in any way?@not-raspberry Thanks. Your first comment about generating code helped.
Is there an equivalent to bundle install for lein? lein install
? I am trying to build a dockerfile where all the deps get installed. Currently when I run lein run
the deps get installed each time. Thanks