Fork me on GitHub
#clojure
<
2018-09-17
>
Lutz06:09:49

Hi everybody! I have a question about Onyx. I have a job where I want to use watermark triggering to use windows of segments. It works in a toy example, and time-based triggering works in the real application. However, watermark triggering does not work in the real application. What can be the cause and how can I verify and fix that?

schmee07:09:58

I would try asking this in #onyx

Lutz07:09:04

I was just pointed to the possibility that completion of the job by closing the input channel may trigger the watermark in the toy example...

lmergen07:09:02

@lutz.buech closing the input channel will cause the job to end, not the watermark to be triggered

lmergen07:09:17

also, #onyx is a better place to discuss this

Lutz07:09:14

Thanks for the advice!

borkdude08:09:58

When using clojure.core.memoize/ttl is it possible to evict a result after some time, regardless if it has been requested? so the ttl is not reset on a cache hit

borkdude08:09:05

this may already the standard behavior

kwladyka10:09:34

cli question :aliases {:test {:extra-paths ["test"]}} What is the difference between clj -C:test vs clj -A:test ? I guess there is no difference. So my question is what is the point of having -C and -A? Can i use always -A?

Alex Miller (Clojure team)12:09:33

I think in general you can just use -A and ignore the rest most of the time

arohner11:09:08

I remember seeing a while back a gist / blog post about inspecting protocol implementations to see which methods an instance implements, etc. Does anyone have a link, or a hint to google for?

Alex Miller (Clojure team)12:09:29

The protocol name will eval to a map with all the protocol state if that helps

arohner12:09:15

I thought there was something else as well? A place where you could see that type A only implements 1 out of 2 methods on protocol Bar?

emil0r12:09:29

Shouldn’t it always implement all the methods?

Alex Miller (Clojure team)13:09:55

that info is in the protocol map

Alex Miller (Clojure team)13:09:07

because the method impl will be missing in the map

Alex Miller (Clojure team)13:09:29

user=> (defprotocol Bar (a [_]) (b [_]))
Bar
user=> (extend-protocol Bar String (a [_] "a"))
nil
user=> (pprint Bar)
{:on user.Bar,
 :on-interface user.Bar,
 :sigs
 {:a {:name a, :arglists ([_]), :doc nil},
  :b {:name b, :arglists ([_]), :doc nil}},
 :var #'user/Bar,
 :method-map {:b :b, :a :a},
 :method-builders
 {#'user/b
  #object[user$eval146$fn__147 0x4983159f "[email protected]"],
  #'user/a
  #object[user$eval146$fn__158 0x44e3a2b2 "[email protected]"]},
 :impls
 {java.lang.String
  {:a
   #object[user$eval195$fn__196 0x68ead359 "[email protected]"]}}}

Alex Miller (Clojure team)13:09:48

:sigs tells you the methods in the protocol, :impls lists the method impls per type

Alex Miller (Clojure team)13:09:03

one important missing thing here though are inline protocol impls for records/types

Alex Miller (Clojure team)13:09:40

I don't think there is any way to discover that short of calling protocol methods on an instance and getting an UnsupportedOperationException

Sal14:09:47

what do people use to speedup the startup time of executing clojure code in dev?

mpenet14:09:09

not starting up often is the key

Sal14:09:27

I tried using something called Drip but it’s broken

mpenet14:09:33

ex: I started a single session today

Sal14:09:52

what do you use to keep the session alive?

mpenet14:09:16

emacs, single repl session and you keep it alive all the way

mpenet14:09:54

there's quite a few videos on youtube about repl driven developement (via emacs, vi or cursive) with clojure, should get you started

Sal14:09:51

Ok cool. Thank you

misha16:09:04

if I bind lazy-seq to something in let, am I holding to its head now?

noisesmith16:09:59

no, clojure's smart enough to clear locals in let forms once you stop using them

noisesmith16:09:31

the gotcha is if you let it escape scope (clearing can't be done then) or turn off locals clearing for debugging

misha16:09:00

how does holding to lazy-seq's head usually look like then?

noisesmith16:09:27

iterating over it but also returning it is the simple example

misha16:09:29

so unless I return it from fn enclosing let - I'm fine?

noisesmith16:09:49

or assign it to something with scope outside the let

noisesmith16:09:30

or consume it twice, with one consumer much slower than the other(?)

ghadi16:09:37

concretely the thing to avoid is:

(let [COLL (big lazy seq)]
  (some-other-process-that-uses-the-whole-list COLL)
  (doseq [i COLL]
    (use i)))

misha16:09:12

and the holding-part is (some-other-process here?

ghadi16:09:30

no it's not slow -- it will expand the collection like an accordion

noisesmith16:09:30

the slow one is doseq - it doesn't start until the other returns

misha16:09:46

or the fact that doseq - is the last form?

ghadi16:09:47

and interfere with the quality of doseq which doesn't hold the head

noisesmith16:09:29

@misha if you picture it- the external process can expand COLL, but since doseq is using the same coll but hasn't run yet, the realized results can't be cleared

noisesmith16:09:35

I like the accordion metaphor, yeah

ghadi16:09:36

actually in this case it will be ok... Sigh, I need more coffee

misha16:09:57

so coll gets expanded by some-other-process, and gets kept in memory until doseq finishes

noisesmith16:09:15

@ghadi so that would mean that items in COLL are realized twice? I don't see how else it would be OK

misha16:09:24

maybe if some-other-process is lazy too?

noisesmith16:09:50

then it's a no-op

misha16:09:54

@noisesmith can you give a short example of "assign it to something with scope outside the let"?

noisesmith16:09:42

(def state (atom [])) ... (defn foo [] (let [c (some-huge-lazy-thing)] (swap! state conj c) (doseq [el c] ...))) - c leaves scope via swap!, now the head is held onto and can't be cleared

misha16:09:32

thank you

misha16:09:47

another question: does it even make sense to have an atom in a :dynamic var to use it from multiple threads?

noisesmith16:09:33

I can't think of a case off the top of my head where those behaviors would work together - one says "you can change this but only in this thread scope and not visible to sibling or parent scopes" and the other says "you can change this and it will be visible to all threads"

misha16:09:49

binding will work only for current thread, not for others (if I, say, pmap inside binding form), won't it?

noisesmith16:09:12

right, the reason to use binding is because you want that behavior

noisesmith16:09:19

there's literally no other reason to use it

misha16:09:32

thank you

noisesmith16:09:49

pmap will propagate bindings - I might have misunderstood you

noisesmith16:09:35

binding propagates to child scopes, with things like pmap, future, go this is automatic, with lower level jvm thread construction you might need to propagate it more manually

noisesmith16:09:51

what binding doesn't do is make changes visible to parent or sibling scopes

leonoel16:09:29

not saying that it makes sense, but the clojurescript compiler does that https://github.com/clojure/clojurescript/blob/master/src/main/clojure/cljs/env.cljc

lsantanna18:09:27

hey folks! I am trying to create a macro to add a log layer in my application

(defmacro defn-log [name args body]
  (let [the-name (keyword name)]
    `(def ~name
       (fn ~args
         (let [log1# (log/info (str "begin: " `name))
               log2# (log/debug (str "input for " `name ": " ~args))
               x# ([email protected])
               log3# (log/debug (str "output for " `name ": " x#))
               log4# (log/info (str "ending: " `name))] x#)))))
it’s working for simple cases like
(defnlog ttt [name1] (let [x (+ 1 1)
                                          xy (println name1)] name1)
but cases like doesn’t work.
(defn-log -main [& args] …)

noisesmith18:09:30

what do you expect `name to do in that macro?

lsantanna18:09:46

add the function nameto the log

noisesmith18:09:15

in that case I would expect '~name

lsantanna18:09:41

my output would be something like begin: tttt input for: tttt name1 output for : tttt : value of x ending tttt

noisesmith18:09:42

user=> (defmacro foo [n] `(println `n))
#'user/foo
user=> (foo a)
user/n
nil
user=> (defmacro foo [n] `(println '~n))
#'user/foo
user=> (foo a)
a
nil

lsantanna18:09:35

cool will change that

lsantanna18:09:08

if i use the simple case it works fine. with the change you suggest

lsantanna18:09:16

but with

(defn-log -main [& args] …)

lsantanna18:09:29

i got an Unable to resolve symbol: & in this context,

noisesmith18:09:03

perhaps you also want 'args in the log instead of args - that's likely the error

noisesmith18:09:54

the problem is that there are items in your arglist that can't actually be resolved at runtime - so you either need smarter arglist parsing, or you want to just show the literal arglist

lsantanna18:09:35

yes, that is the problem

lsantanna18:09:44

i was trying to figureout how defn does it

noisesmith18:09:45

a third option is to insert (keys &env) into your output form, which leads to locals being printed at runtime

noisesmith18:09:03

this also shows let bindings, so you would likely want to inject that before the let form

lsantanna18:09:02

I see, will try to change here. thx 🙂

awb9919:09:38

does someone know how I can convert a dom element to a clojurescript value ? (js->clj (gdom/getElement "myId") ) does not return anything useful.

noisesmith19:09:11

I think the key would be the Dom element api in js - there should be some method to get the markup or structure

awb9919:09:13

thanks!! (.getAttribute (gdom/getElement "myId") "data-month")

awb9922:09:52

I have some Figwheel issue: In the repl, it works, and I can build it. But Figwheel Complains in the browser-window

awb9922:09:23

^--- No such namespace: mynodes, could not locate mynodes.cljs, mynodes.cljc, or JavaScript source providing "mynodes" 52

awb9922:09:43

I am getting a list of dom nodes, and then going forEach on them.

awb9922:09:51

The mynodes variable is defined in the let.

awb9922:09:05

Use of undeclared Var mynodes/forEach at line 51, column 7 in file src-client/client/dom.cljs

dpsutton22:09:12

it's not complaining about a var mynodes it's complaining about mynodes/forEach. it's not finding a mynodes namespace

dpsutton22:09:46

i'm guessing you want a doseq here or run!

hiredman22:09:51

(.foreach mynodes ...)

hiredman22:09:09

foo/bar is namespace qualified symbol syntax

hiredman22:09:22

mynodes is not a namespace, it is a js object

hiredman22:09:35

. is for host method calls

awb9922:09:48

I cannot do doseq,

awb9922:09:56

because nodes is not seq able.

bhauman22:09:39

(.forEach mynodes)

awb9922:09:53

why does the repl accept my fucked up syntax then??

dpsutton22:09:11

correct. i didn't know gdom/.. returned js objects 🙂

hiredman22:09:59

clojurescript is kind of meh

opieop 4
awb9922:09:34

@bhauman it works! cool !

john03:09:01

Also, you can call array-seq on node lists, since they're "array like" things

dpsutton22:09:46

your syntax is fine. just semantically it doesn't mean anythign

awb9922:09:36

@hiredman! Yeah thanks!!

arrdem22:09:21

Is there a way to make clj non-strict about missing aliases?

seancorfield22:09:21

@arrdem Earlier versions silently ignored them -- but people complained about that which is why the new version complains...

arrdem22:09:26

Also it looks like (if you hack the script to let you use multiple deps files) paths from deps files are always treated relatively, they’re never normalized to absolute paths with respect to the location of the deps file.

arrdem22:09:47

@seancorfield thanks for the context.

seancorfield22:09:29

That other issue sounds very much like the (known) issue of local/root deps not working when combined with other deps...

arrdem22:09:53

Probably related - yeah.

Alex Miller (Clojure team)22:09:23

Yes, that’s the problem

arrdem22:09:58

@alexmiller thanks for the fast turnaround on the default deps thing, would you be interested in an absolute path patch for clojure.tools.deps.alpha.reader?

Alex Miller (Clojure team)23:09:36

what’s the problem we’re talking about?

Alex Miller (Clojure team)23:09:03

btw #tools-deps is prob better for stuff like this discussion

Alex Miller (Clojure team)23:09:31

I’m curious about the scenario above where being lax about missing aliases would be helpful to you