Fork me on GitHub

@edward.banner FWIW, the topic covered in that gist is now formally documented as part of the stuff here


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"
  (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 futures 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

Michael Fiano09:03:41

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?

Michael Fiano10:03:32

That worked, thanks.


@mfiano easier to just put a (def <name multimethod> nil) before the declaration of the multimethod

👍 4
Russ Olsen11:03:27

@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.

Michael Fiano11:03:15

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
  (:arglists (meta #'fun)))
doesn't work? I get CompilerException java.lang.RuntimeException: Unable to resolve var: fun in this context, compiling

Alex Miller (Clojure team)18:03:10

#’fun literally means “the var fun”

Alex Miller (Clojure team)18:03:49

(defn arglists [fun] (:arglists (meta (resolve fun))))
(arglists 'defn)


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

Alex Miller (Clojure team)18:03:10

arguments to a function are evaluated before invocation so if your goal is to call (arglists defn), you’ll need a macro

Alex Miller (Clojure team)18:03:25

which receives its arguments unevaluated

Alex Miller (Clojure team)18:03:35

(defmacro arglists [fun] `(:arglists (meta (resolve '~fun))))
(arglists defn)


Ahh I think I see! What does the '~ before fun do?

Alex Miller (Clojure team)18:03:57

~ evaluates the arg within the scope of the `

Alex Miller (Clojure team)18:03:25

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