This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2015-11-28
Channels
- # admin-announcements (21)
- # beginners (102)
- # boot (8)
- # cider (40)
- # cljsrn (2)
- # clojure (52)
- # clojure-nl (2)
- # clojure-russia (6)
- # clojure-taiwan (2)
- # clojure-uk (1)
- # clojurescript (363)
- # datavis (22)
- # datomic (69)
- # emacs (4)
- # hoplon (1)
- # immutant (2)
- # jobs-rus (13)
- # ldnclj (6)
- # lein-figwheel (2)
- # leiningen (9)
- # liberator (1)
- # off-topic (1)
- # om (68)
- # onyx (28)
- # parinfer (3)
no because lazyness happens for runtime stuff, while with a macro you are changing forms at compile time
you don't have lazy forms at compile time
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?
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
@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))))
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
@derwolfe then (handle-other-ch v)
can choose to give the old timeout
to the recur, or create a new timeout
value
sander: herrwolfe: simple solution is to inject the timeout channel, that way if you wanted to test, you inject an already closed channel.
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?
I want to point out that I will deal with a backend application (zero html templates, UI, etc.).
@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
@rcanepa: might help to start with an introduction to ring. https://github.com/clojure-cookbook/clojure-cookbook/blob/master/07_webapps/7-01_ringintroduction.asciidoc
@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/
Ok. I will. Where should I look if I want a “reloadable” environment?… Do I have work with a leiningen plugin?
@rcanepa: there's a wrap-reload Ring middleware, but personally I don't use it, I use a REPL-based workflow
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'.
if i’m implementing batching by pulling items from a channel, conj
ing them to a collection, and then acting depending on the count
of that collection, should i use a list or a vector?
like i think conj ‘() thing
is faster than conj [] thing
, and i think count my-vec
is faster than count my-list
@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.
@seancorfield: I wouldn't count (sorry) on that. we're rarely manipulating lists in clojure, and seqs are never guaranteed to be Counted
As long as you have a PersistentList you can "count" on that.
So you just need to ensure you don’t turn it into a seq
And in fact (-> (conj () :thing) (conj :a :b :c) seq type ancestors)
still has Counted
in there so...
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)
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).
And of course if you map
or filter
it you’ll lose Counted
.
Of course now you’ve made me curious and (into () (map something) my-list)
uses tranducers and preserves Counted
...
It’s stuff like this that makes me really love Clojure 😸
Well, I meant more that using (map something)
with into
will let you keep the Counted
property.
really? for me it's stuff like this that makes me go "eh" about clojure it's really non obvious that there should be a difference between stuff that prints and behaves the same
I guess one man’s abstraction is another man’s frustration? 😆
True, printing Clojure data structures can be very misleading… which means round-tripping them can also be surprising at times.