This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-03-28
Channels
- # aws (1)
- # beginners (30)
- # boot (7)
- # cider (52)
- # clara (91)
- # cljs-dev (33)
- # cljsjs (1)
- # clojure (447)
- # clojure-brasil (3)
- # clojure-dev (16)
- # clojure-dusseldorf (5)
- # clojure-filipino (1)
- # clojure-italy (29)
- # clojure-sanfrancisco (5)
- # clojure-spec (62)
- # clojure-uk (37)
- # clojurescript (145)
- # clojurewerkz (1)
- # code-reviews (12)
- # community-development (157)
- # cursive (5)
- # datascript (1)
- # datomic (27)
- # editors (42)
- # emacs (5)
- # fulcro (31)
- # hoplon (2)
- # jobs (2)
- # keechma (1)
- # lumo (31)
- # off-topic (2)
- # om (1)
- # onyx (13)
- # parinfer (8)
- # re-frame (13)
- # reagent (32)
- # remote-jobs (4)
- # shadow-cljs (103)
- # spacemacs (15)
- # specter (10)
- # sql (1)
- # tools-deps (35)
- # unrepl (13)
@edward.banner FWIW, the topic covered in that gist is now formally documented as part of the stuff here https://clojurescript.org/guides/ns-forms
It looks like your problem above was that you were defining your macro at the REPL instead of in a .clj
file.
Hi everyone, so I have some cases with concurrency here. I have a list of hash-maps in which each defines an item. Each of this item needs to get "expanded" by calling another service. For example if I have this list of items:
[{:type "article"
:id 123}
{:type "video"
:id 456}
{:type "poll"
:id 111}]
And reduce them using a transducers:
(defmethod resolve-item "article"
[article]
(expensive-network-call article))
(into [] (comp (map resolve-item) (map process-further)) items)
When I use a map here, how the network call will exactly occur? Will it be executed sequentially for each item? If I use future for the expensive network call then realizing it later in the same function, will it make any difference?You'd need to make two passes @hawari.rahman17 -- the first to create the future
s for the expressions and the second to deref
them when you needed the result.
But transducers work left-to-right so you're going to lose some concurrency there. You might want to look at the reducers
library and fold
.
When using transducer basically what happened is resolve-item
and process-further
will be applied for each item sequentially, is that what you're saying @seancorfield?
- resolve-item 1st item - process-further 1st item - resolve-item 2nd item - process-further 2nd item ... Is that correct?
Yes, it is sequential.
Alright, thanks for the pointers @seancorfield
I have a multimethod that isn't dispatching properly, but renaming it seems to work. Is there a way to delete a multi and all of its methods so I can start over without restarting my jvm?
That worked, thanks.
@mfiano easier to just put a (def <name multimethod> nil) before the declaration of the multimethod
@mfiano There are two places in Clojure which drive me a little crazy since they don't redefine quite as cleanly as everything else: multimethods and records and protocols (well maybe that's 3). There are good reasons for both but it still catches me every so often.
Ah yeah, though nothing I'm not used to. Common Lisp's methods are even more flexible and have problems in this regard too.
Any idea why
(defn arglists
[fun]
(:arglists (meta #'fun)))
doesn't work? I get CompilerException java.lang.RuntimeException: Unable to resolve var: fun in this context, compiling
#’fun literally means “the var fun”
(defn arglists [fun] (:arglists (meta (resolve fun))))
(arglists 'defn)
something like that
the ` before defn means don't evaluate this, right?
Is there any way that you could end up calling it with (arglists defn)
? Using (resolve 'fun)
doesn't seem to work for it
arguments to a function are evaluated before invocation so if your goal is to call (arglists defn), you’ll need a macro
which receives its arguments unevaluated
(defmacro arglists [fun] `(:arglists (meta (resolve '~fun))))
(arglists defn)
Ahh I think I see! What does the '~
before fun
do?
~ evaluates the arg within the scope of the `
that will evaluate the input to a symbol, but then you need to quote ' that symbol to avoid it from being evaluated
Okay! So roughly speaking, we're doing pretty selective evaluation of things here
Cheers for putting up with my lack of being familiar with this stuff