Fork me on GitHub
#clojure
<
2015-11-28
>
richiardiandrea00:11:13

no because lazyness happens for runtime stuff, while with a macro you are changing forms at compile time

richiardiandrea00:11:36

you don't have lazy forms at compile time

derwolfe03:11:50

when writing code using core.async and timeouts, is there a generally accepted way of testing timeouts without waiting for the full timeout period to be reached?

sander10:11:07

herrwolfe: with testing you mean checking whether they timed out? use alts!

derwolfe14:11:18

sander: actually I mean being able to advance the clock the amount of the timeout. E.g. A test has a function that uses a timeout channel inside of a go loop, on a new timeout it does something interesting. I'd like to advance the clock an arbitrary amount of time so that the test need not wait for the entire timeout period to complete

sander14:11:06

@derwolfe: not sure what you want exactly, but i often use something like this:

(a/go-loop [timeout (initial-timeout)]
  (let [[v ch] (a/alts! [timeout other-ch stop-ch])]
    (condp = ch
      timeout  (recur (handle-timeout))
      other-ch (recur (handle-other-ch v))
      stop-ch  (handle-stop))))

grounded_sage14:11:10

Has anyone used the pulsar library? Been getting interested in Elixir but if I can get the same benefits of lightweight processes and supervisors while sticking with Clojure that definitely interests me

sander14:11:31

@derwolfe then (handle-other-ch v) can choose to give the old timeout to the recur, or create a new timeout value

ghadi15:11:54

sander: herrwolfe: simple solution is to inject the timeout channel, that way if you wanted to test, you inject an already closed channel.

ghadi15:11:03

forget about messing with the clock, you can't

sander15:11:11

ah missed the testing context in the question

derwolfe15:11:19

ghadi sander: thanks!

meow16:11:42

I'm stuck on trying to figure out how to differentiate 0.0 from -0.0 in clojure.

meow16:11:54

pos? and neg? don't help

bronsa16:11:09

@meow: I'm afraid your best option is to use .equals

meow16:11:07

@bronsa: I think I can work with that. Thanks! simple_smile

rcanepa18:11:10

Hi everyone. I recently finished my first book on Clojure (Clojure for the Brave and True) and I would like to put this knowledge in practice creating a REST API. I have experience developing REST API, but I am a complete novice on Clojure. I have been reading about Ring, Compojure, Pedestal, Friends/Buddy, etc., but I got very confuse about where should I start. Any recommendation on this?… should I start from the basics (Ring/Compojure) or should I try something more elaborate like pedestal?

rcanepa18:11:29

I want to point out that I will deal with a backend application (zero html templates, UI, etc.).

griffio18:11:50

@rcanepa: Welcome, a couple of suggestions for you if you haven't come across them. https://clojure-liberator.github.io/liberator/ - more Restful https://github.com/metosin/compojure-api - adds swagger generation and nice starter template

rcanepa18:11:23

Excellent guys… I wasn’t aware of Liberator or compojure-api.

rcanepa18:11:28

I bought that book yesterday (along with Clojure Applied and the Joy of Clojure)

rcanepa18:11:51

Nice to know that it has a chapter about Ring

val_waeselynck18:11:20

@rcanepa: have a look at luminus too, you won't need all of it but it's nice to have an overview of a complete solution http://www.luminusweb.net/

rcanepa18:11:08

Ok. I will. Where should I look if I want a “reloadable” environment?… Do I have work with a leiningen plugin?

val_waeselynck18:11:43

@rcanepa: there's a wrap-reload Ring middleware, but personally I don't use it, I use a REPL-based workflow

rcanepa18:11:17

Ok… good to know… thanks again guys! Time to work!

waffletower19:11:39

The word 'map' so totally abused in computer science. Clojure is not unique nor innocent (obviously) in this regard. Amazing how many subtle meanings have derived from the latin word for 'napkin'.

bozhidar19:11:59

interesting read

swizzard20:11:57

if i’m implementing batching by pulling items from a channel, conjing them to a collection, and then acting depending on the count of that collection, should i use a list or a vector?

swizzard20:11:59

like i think conj ‘() thing is faster than conj [] thing, and i think count my-vec is faster than count my-list

seancorfield22:11:28

@swizzard: If you look at (-> (conj '() :thing) type ancestors) you’ll see that clojure.lang.Counted is there so (count my-list) should be O(1). And indeed if you look at the source of PersistentList https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/PersistentList.java you can see it maintains an internal _count of its elements.

bronsa22:11:44

@seancorfield: I wouldn't count (sorry) on that. we're rarely manipulating lists in clojure, and seqs are never guaranteed to be Counted

seancorfield22:11:49

As long as you have a PersistentList you can "count" on that.

seancorfield22:11:04

So you just need to ensure you don’t turn it into a seq simple_smile

seancorfield22:11:39

And in fact (-> (conj () :thing) (conj :a :b :c) seq type ancestors) still has Counted in there so...

bronsa22:11:54

yeah, as long as all you do is conj stauff to it, you're safe

bronsa22:11:19

but if you put a cons or some other seq operation, you don't see any change but it suddently moves from O(1) to O(n)

bronsa22:11:30

way too dangerous for me simple_smile

seancorfield22:11:30

Yeah, if you cons onto it, you lose Counted. But you can rest and next it and still have a Counted PL (which actually surprised me).

seancorfield22:11:02

And of course if you map or filter it you’ll lose Counted.

seancorfield22:11:46

Of course now you’ve made me curious and (into () (map something) my-list) uses tranducers and preserves Counted...

bronsa22:11:33

not a property of transducers

seancorfield22:11:34

It’s stuff like this that makes me really love Clojure 😸

bronsa22:11:46

(into () whatever) will be counted

seancorfield22:11:12

Well, I meant more that using (map something) with into will let you keep the Counted property.

bronsa22:11:18

really? for me it's stuff like this that makes me go "eh" about clojure simple_smile it's really non obvious that there should be a difference between stuff that prints and behaves the same

seancorfield22:11:35

I guess one man’s abstraction is another man’s frustration? 😆

bronsa22:11:56

but then again, ArrayLists print like vectors so.. simple_smile

seancorfield22:11:02

True, printing Clojure data structures can be very misleading… which means round-tripping them can also be surprising at times.