Fork me on GitHub
#clojure
<
2018-05-07
>
emccue02:05:55

So I thought that reify was only for interfaces

emccue02:05:17

why can I put this?

the2bears02:05:16

Per the reify docs: Methods should be supplied for all methods of the desired protocol(s) and interface(s). You can also define overrides for methods of Object.

the2bears02:05:58

So you're just overriding toString here.

wei08:05:50

is there a good way to block until an atom changes? basically a synchronous version of add-watch

gklijs09:05:44

@wei never used agents myself, but seems like you need to use them for something like that.

mpenet09:05:20

you can hack something around with a watch and a promise or an async/chan if you need repeated access

mpenet09:05:26

but that's a bit an odd request

wei09:05:37

thanks for the tips. I'm thinking of an alternate solution using core.async's pub sub. can you unsubscribe from a publication? I haven't seen any examples

sobel11:05:36

if you're blocking for something that is observable, you have coded yourself into a corner

sobel11:05:55

if you find the asked solution, you're still facing the corner

vsvn13:05:39

what’s the best way to mock a connection within a with-open for testing?

mpenet15:05:16

depends what you need to pull out of it, but a simple reify/record that implement Closeable should be good enough

wei17:05:57

@matt220, sounds like a reasonable principle and I'd like to learn how to apply it. How you would design this then: a website checkout flow that listens for a particular invoice payment event from the server. I was thinking of using a long-running http request that returns when the payment is made (with a configurable timeout). On the server-side, I'd have a map of invoices so I'd want to block on observing changes to it.

huthayfa18:05:50

hi guys, what is the function that explode the vector into single elements.

dpsutton18:05:35

@huthayfa.ainqawi can you give an example input and output?

huthayfa18:05:00

([1 2 3 4] => 1 2 3 4)

huthayfa18:05:33

it's like destructing, but I don't want to bind the elements to vars

dpsutton18:05:21

Can you show how you would use that function? Because I think a vector or list is exactly what you are wanting

dpsutton18:05:23

Or is this during quoting of lists?

andy.fingerhut18:05:04

If you want to call a function with arguments 1 2 3 4, not [1 2 3 4], and you have [1 2 3 4], you can use apply to do that, but that is specifically for the case of calling a function.

πŸ‘ 4
mg18:05:10

@wei promises might be helpful here.

πŸ‘ 4
manutter5118:05:21

@huthayfa.ainqawi are you perhaps looking for apply?

πŸ‘ 4
dpsutton18:05:32

Also, functions can only return a single value so it's impossible to return all the elements not in some kind of container unless you are in the midst of semiquoting. And even then it just appears to return multiple values

πŸ‘ 4
souenzzo18:05:53

There is some implementation of modPow on clojure.lang.BitInt?

taylor18:05:20

filter (and remove, maybe others) docstring says pred must be free of side-effects. Is this because pred may be invoked multiple times? Why?

tbaldridge18:05:20

There's nothing wrong that will happen if they aren't. I put println calls inside them all the time. It's just bad practice to have side-effects in these places. There is a lot of complexity about how often the predicates are run, if they're run at all, and they may be run in batches of 32 items at once.

tbaldridge18:05:38

So it's bad to have side-effects that are required for correct execution of the program.

tbaldridge18:05:52

But it's also completely safe if you know all the drawbacks.

tbaldridge18:05:12

But if you know all the drawbacks, you won't want to put side-effects inside lazy seq ops. πŸ˜„

dpsutton18:05:57

@U07TDTQNL those predicates can be run more than once? can you think of an example how that is true? ("how often the predicates are run")

tbaldridge18:05:46

the predicate won't be called twice with the same value, but it may never be called. Be called once, be called once, then be called later, or 32 times very quickly, then never again...

tbaldridge19:05:06

there's very little predictability to it all, and with side effects that predictability is sometimes important.

dpsutton19:05:19

ah ok. thanks πŸ‘

Alex Miller (Clojure team)19:05:01

the most important aspect is that those seq functions are chunked and batched in elements of 32 so side effects may be effected for elements you never use

πŸ‘ 8
joaohgomes18:05:18

@souenzzo have you tried: (type (-> (clojure.lang.BigInt/fromLong 100) .toBigInteger))?

souenzzo19:05:56

Yep. I'm using it. But is that the right way?

eraserhd18:05:55

@taylor Clojure sometimes uses chunked sequences, and when it does, it applies the predicate to the whole chunk, not just what is consumed.

dpsutton18:05:14

ie, (take 3 (map side-effecty big-coll)) might do more work than you think

taylor18:05:25

so it’s to address a concern when pred might be applied to more items in the input collection than is consumed

taylor18:05:41

not that it might be invoked more than once per item

dpsutton18:05:55

also you don't know when it would run necessarily. so it may not have the correct resources, etc.

πŸ‘ 4
Wesley Matson19:05:50

Is there a way to configure lein-ring to generate a META-INF/context.xml when running lein ring uberwar?

Wesley Matson19:05:39

Figured it out, one can add a :war-resources-path to the root project.clj

Fereidoon22:05:42

Is there a Conj channel as well?

hiredman22:05:47

the conj usually has a popup separate slack instance for it that you are invited to if you have registered for the conj a little bit before the conj

dpsutton22:05:28

#events for general events