Fork me on GitHub
#beginners
<
2018-03-28
>
mfikes01:03:47

@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

mfikes01:03:26

It looks like your problem above was that you were defining your macro at the REPL instead of in a .clj file.

hawari04:03:56

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?

seancorfield04:03:18

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.

seancorfield04:03:03

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.

hawari04:03:22

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?

hawari04:03:26

- resolve-item 1st item - process-further 1st item - resolve-item 2nd item - process-further 2nd item ... Is that correct?

seancorfield05:03:06

Yes, it is sequential.

hawari06:03:19

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.

gabriele10:03:26

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

OctarineSorcerer17:03:52

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

alexmiller18:03:10

#’fun literally means “the var fun”

alexmiller18:03:49

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

alexmiller18:03:12

something like that

OctarineSorcerer18:03:14

the ` before defn means don't evaluate this, right?

OctarineSorcerer18:03:55

Is there any way that you could end up calling it with (arglists defn)? Using (resolve 'fun) doesn't seem to work for it

alexmiller18:03:10

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

alexmiller18:03:25

which receives its arguments unevaluated

alexmiller18:03:35

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

OctarineSorcerer18:03:42

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

alexmiller18:03:57

~ evaluates the arg within the scope of the `

alexmiller18:03:25

that will evaluate the input to a symbol, but then you need to quote ' that symbol to avoid it from being evaluated

OctarineSorcerer18:03:17

Okay! So roughly speaking, we're doing pretty selective evaluation of things here

OctarineSorcerer18:03:37

Cheers for putting up with my lack of being familiar with this stuff