This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-03-01
Channels
- # aatree (1)
- # alda (1)
- # announcements (3)
- # beginners (10)
- # boot (44)
- # braid-chat (6)
- # cbus (5)
- # cider (19)
- # cljs-dev (5)
- # cljsrn (11)
- # clojure (203)
- # clojure-austria (1)
- # clojure-canada (1)
- # clojure-germany (2)
- # clojure-poland (46)
- # clojure-russia (38)
- # clojurescript (79)
- # clojuresque (2)
- # code-reviews (11)
- # core-async (6)
- # cursive (11)
- # datomic (12)
- # dirac (91)
- # hoplon (8)
- # juxt (14)
- # ldnclj (7)
- # lein-figwheel (6)
- # leiningen (18)
- # off-topic (3)
- # om (230)
- # om-next (7)
- # onyx (31)
- # parinfer (1)
- # proton (1)
- # re-frame (44)
- # reagent (2)
- # rethinkdb (10)
- # spacemacs (5)
- # yada (24)
hi guys, for example I have a list of map ({1 nil} {2 nil})
how to transform it to a map {1 nil 2 nil}
i could be wrong, but i think sente is designed to be the communication layer between the server and client for which you are in control of, rather than a way to interface with external applications.
well, if you have your macro interpret that expression, then you'll be able to do that
hi guys, can we pass custom function in (cond->)
. For example: (cond-> {} predicate #(if ...)
Am I going about it the wrong way or is the teardown order of components that communicate using core.async channels the wrong way round if you’re using stuart sierra’s Component?
assuming normally down-stream components shut down if their up-stream channel closes
@spacepluk: that's not appropriate here
@joost-diepenmaat: It is certainly possible to use core.async and Component together. You have to figure out for yourself what the appropriate behavior for start/stop should be.
When I use both together, I tend to manage the closing of channels and go
blocks independently from Component stop
.
@spacepluk: you mean something like:
boot.user=> (def . 42)
#'boot.user/.
boot.user=> .
42
?@spacepluk: ah.. scrolled up a bit, I see
@tolitius hmm interesting it doesn't work when you put a function in the var and try to call it
@spacepluk: if this is just for learning purposes, you can (redefine) use other symbols, like *
for example. the reader marcros and special forms won't work of course:
boot.user=> (def * (fn [] 42))
#'boot.user/*
Hey all! I have a strange problem with Riemann + InfluxDB here. I'm sending events from an app to Riemann, which collects them and sends in batches to Influx (in other case Influx dies under load). And I have two apps, one in Python and another in Clojure. Python app then works normally, all events from there appear in Influx.
With Clojure it's weird. Only last even from the given second ends up in Influx.
I've tried to add :time information to an event (I don't in Python). Didn't help.
Strange thing is that when I log events inside of riemann, it shows :time 1.456837234149E9
in events from python and :time 1456838821
in events from Clojure. I never set this time in Python and I don't think client I use (bernhard) does.
Any points on where to look next? Riemann successfully produces all events in debug log, but I want them in Influx.
@stuartsierra: thanks I’ll give that a try
is there a function like concat but which keeps the first arg’s type?
like, concat but return a vector
that returns a lazy seq
something like (f [1 2] [3 4]) => [1 2 3 4]
into!
I’d like to make a REST API server, with URLs modeled around resources, the way rails “suggests” one does.
This is clearly something that is easy enough to code with ring. I was wondering if there’s a library that already does this.
@eraserhd: The 2 closest things that I know of are compojure-api and liberator. Neither are database backed, but compojure-api will validate against a schema.
@eraserhd: also #C0702A7SB https://github.com/juxt/yada
eraserhd: if you need any help with liberator or yada, there are channels for those libs.
@asolovyov: that clojure timestamp is a count of seconds since jan 1 1970.
in your riemann debug logs you may have every event but you probably have duplicated timestamps for clojure events?
is there a more elegant way to classify something as a function, sequential, or map? etc
(fn [x] (cond (clojure.test/function? x) :fn (sequential? x) :sequential (map? x) :map :default :unknown))
Is there a reason you're not using clojure.core/fn?
?
@jonahbenton: I can, of course - there are many events happening in the same second
@eraserhd: I made library which handles route creation for rails-style rest resources with liberator https://github.com/flyingmachine/liberator-unbound
it’s kind of funky and I might not have explained it well in the readme but it might do what you want
the examples at the bottom of the readme show how you can generate the routes
simple question, how do I quote the deref
symbol @
, so it stays @
instead of clojure.core/deref
@josh.freckleton: In what context?
@nonrecursive: I quick-read the README, and am not sure I grok it. I’ll spend more time on it later.
@eraserhd: yeah the readme is kind of garbage - probably only useful to me, within 48 hours of when I wrote it, a year ago. it definitely requires some familiarity with liberator. I think that Liberator on its own would be a good choice though
@eraserhd: I have a function returning a quoted list with the deref inside, and I want to compare it in a test. so it returns '(some-f @some-atom)
and in the test, I want to make sure that that quoted list equals an identical one, and I'm assuming that when you compare quoted lists, deref != @
in a test. Does that make more sense?
By the way: for anyone who followed my trail getting Alia and Hayt working for a huge Cassandra push - I got that working a few days ago and Alia is turning out to be quite the workhorse (or maybe racehorse is a better term). I'm getting 19K entities per second pushed to Cassandra. Thanks to everyone who helped as I figured out this library.
@eraserhd: so there's now way for it to stay a @
, but @
still ==
deref
in a test because it expands at compile time before the test? am I getting this?
@josh.freckleton: I’m pretty sure that’s correct
@nonrecursive: (= '(clojure.core/deref myatom) '(@myatom))
=> false
in my repl, should this not be true then?
so if you just do ’(@myatom)
it expands to ((clojure.core/deref myatom))
try (= '(clojure.core/deref myatom) '@myatom)
ahh, genius. I've gotta look out for how macros expand, that's bit me before too. Thanks so much @nonrecursive!
@josh.freckleton: @
is a “reader macro”, which is different from a normal macro, FYI.
reader macros expand at read time, before compile/macro-expansion time
@alexmiller: wo, I had no idea there were read time, as well as compile time macros, that makes sense now. Are there any other flavors of macros? Any other reader macros?
ok, I'll look it up to learn more, ya the #()
macro bit me once before when I was trying to thread it with (->)
I didn't realize it was a read time thing though, that's really cool to know we have that!
reader macros are not user-extensible though - they are fixed in the reader (which is different than other Lisps)
that is one of the very good decisions made in clojure - extensible reader macros are a pain for IDEs and any tools that want to analyze source code.
@alexmiller: good to know, that was my next question I was just going to look up. Everyday I'm more impressed with Clojure, there's like this total "honeymoon" phase between us right now 😉
of course there is the #= reader macro escape hatch but you have to be in double secret Clojure club to use that
are you in double secret Clojure club?
it's just eval (at read time)
ohhh, haha , i was googling furiously to find it
https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/LispReader.java#L1096-L1137
@josh.freckleton: you might find this helpful https://yobriefca.se/blog/2014/05/19/the-weird-and-wonderful-characters-of-clojure/
@nonrecursive: Awesome, that's a fantastic reference, thanks!
I need forcat
(defmacro forcat
[binding body]
`(apply concat (for binding body)))
or maybe reduce would be smarter
ah, of course!
I want to get my Compojure app upgraded to
[org.clojure/clojure "1.7.0"]
but have been usuccessful with my usual hack...just take everything to the head. Is there a migration guide hanging around out there that instructs me how to move this stuff to clojure 1.7.0? Google has failed me, likely because I don't know exactly what to ask.
[org.clojure/clojure "1.6.0"]
[ring/ring-core "1.3.2"]
[ring/ring-jetty-adapter "1.3.2"]
[metosin/ring-swagger-ui "2.0.24"]
[metosin/compojure-api "0.17.0" :exclusions [com.fasterxml.jackson.core/jackson-core]]
thanks @hiredman I should have thought of that
The first ring of hell begins with some Arity Exception FAIL (Arity Exception...ultimately instaparse)
As I baby step my way out of that...I end up at a point where everything runs, but the swagger page 500 errors
I don't have the detailed stacktraces...I suppose I can get that...but I was hoping that someone had been this path and I could read some blog post or something rathere than trying to compose the answer in my head one library at a time
geez, this is not how semantic versioning is supposed to work… 😞
please excuse me...I'm new to this
upgrading to 1.x should not break things that worked in 1.y
actually, I have to run, but I don't know of any reason that 1.7.0 shouldn't "just work", so I doubt there exists a some kind of migration guide. the more specific you can be (including stacktraces) the easier it will be for others to diagnose and offer assistance
do you have any AOT output?
sad, but true...here is the first ring of hell
have you tried “lein clean"
WARNING: update already refers to: #'clojure.core/update in namespace: clojure.math.combinatorics, being replaced by: #'clojure.math.combinatorics/update
Exception in thread "main" clojure.lang.ArityException: Wrong number of args (2) passed to: StringReader, compiling:(abnf.clj:189:28)
at clojure.lang.Compiler$InvokeExpr.eval(Compiler.java:3628)
at clojure.lang.Compiler$InvokeExpr.eval(Compiler.java:3622)
at clojure.lang.Compiler$DefExpr.eval(Compiler.java:439)
it goes on for a while
thats the thing caused by the instaparse no good
yes, Clojure added a clojure.core/update function
I have tried
lein clean
do you know where the dependency on Instaparse is coming from?
Yes...compojure:1.3.1 which is there due to metrosin/compojure-api:0.17.0
I think the root cause of my fail is that, somehow, the metosin/ring-swagger-ui stuff, as I upgrade it, has breaking changes to the "annotation", for lack of a better name, of my routes
looks like Compojure 1.3.3 fixed the incompatibility between Instaparse and Clojure 1.7
interesting… Instaparse was depending on some internal Clojure details and not the public API
OK. So whats the magic I use to figure out which metosin/compojure-api brings in compojure 1.3.3?
so this is a case where Clojure adhered to semantic versioning, but using an undocumented API caused problems… interesting!
lein deps :tree > deps.txt
again, excuse my ignorance...I'm new to this
no problem at all, this is hard stuff
dependency hell
at least Leiningen, in my experience, is better than dependency management in Ruby or other languages I have worked in
lein deps :tree
will output the full dependency tree so you can see what’s requiring what
yeah...I'm there compojure-api is bringing it in
[metosin/compojure-api "0.17.0" :exclusions [[com.fasterxml.jackson.core/jackson-core]]]
[cheshire "5.4.0"]
[com.fasterxml.jackson.dataformat/jackson-dataformat-cbor "2.4.4"]
[com.fasterxml.jackson.dataformat/jackson-dataformat-smile "2.4.4"]
[tigris "0.1.1"]
[compojure "1.3.1"]
[clout "2.1.0"]
[instaparse "1.3.4" :exclusions [[org.clojure/clojure]]]
[medley "0.5.3"]
[metosin/ring-http-response "0.5.2"]
[metosin/ring-middleware-format "0.5.0"]
[clj-yaml "0.4.0"]
[org.yaml/snakeyaml "1.5"]
[com.cognitect/transit-clj "0.8.259"]
[com.cognitect/transit-java "0.8.269"]
[com.fasterxml.jackson.datatype/jackson-datatype-json-org "2.3.2"]
[org.json/json "20090211"]
[org.apache.directory.studio/org.apache.commons.codec "1.8"]
[org.msgpack/msgpack "0.6.10"]
[com.googlecode.json-simple/json-simple "1.1.1" :exclusions [[junit]]]
[org.javassist/javassist "3.18.1-GA"]
[org.clojure/test.check "0.5.9"]
[com.ibm.icu/icu4j "54.1.1"]
[org.clojure/core.memoize "0.5.6"]
[org.clojure/core.cache "0.6.3"]
[org.clojure/data.priority-map "0.0.2"]
[ring "1.3.2"]
[ring/ring-devel "1.3.2"]
[clj-stacktrace "0.2.7"]
[hiccup "1.0.5"]
[ns-tracker "0.2.2"]
But I don't know what I need to do to that to get it to version up compojure to 1.3.3
@robertkuhar: It looks like compojure-api 0.19.3 is the first version to use compojure 1.3.3
Ah...OK. I've been there
Thats the point where I had everything working...except the BLoody swagger page
Hmmm. Maybe I've stumbled upon what I need: https://github.com/metosin/compojure-api/wiki/Migration-from-Swagger-1.2-to-2.0
Yeah, it looks like 0.19.3 pulls in ring-swagger 0.19.4, which pulls in ring-swagger-ui 2.0.24
Maybe I need to "stop, drop, and roll". I dont' fully understand the BREAKING comments on https://github.com/metosin/compojure-api/releases/tag/0.19.0
what if you explicitly require a higher version of compojure?
I’m not sure how that works
yeah...I've not tried that
see what happens if you require the latest compojure in your project’s deps
I'll beat on this a little longer on my end. Thanks
I’m assuming you can’t upgrade to a recent version of compojure-api because you want the Swagger 1.2 support?
If I could figure out how to get out of Swagger 1.2, that is the better path out
I'll do the experiment to get to compojure-api https://github.com/metosin/compojure-api/releases/tag/0.19.3
and come back with what's broken at that point
in any event, I won't bug you guys until I get better information
Good luck!
Would people say that one of the major strengths of Clojure is having no syntax and therefore being able to become any DSL most useful?
I've had kind of a mind shift lately which was thinking about how languages capture domains and dominate them to the point of making a language feel like a simple config file
Almost when you feel like you're "programming" you're already using a language ill suited to the task
Wow! This looks cool http://www.lambdanative.org/
kamuela: the no syntax thing is something I see repeated about different lisps here and there, and I think it is silly
and every macro you write, effectively has its own syntax, but it tends to be grounded in that base level
creating a function relies of different bits of syntax depending on how you want to do it
fn of course can let you have a local name for the function, and different arities for the function, and each arity can use the destructuring syntax, and each aritiy can use the pre and post condition syntax
if anything, macros give you more syntax than other languages, but the syntax is grounded in the set of forms the reader will accept, very similar to tagged literals in the reader
a claim I see repeated in similar places to "lisp as no syntax" is "in lisp you write the ast directlly"
having spent some time with the clojure compiler and written some toy compilers, that claim also strikes me as bunk
How do I drop the time part of a datetime instance?
so only the date from (java.util.Date.)
currentoor: that is kind of complicated, java.util.Date by definition has a time component, so you cannot really "drop" that information, the best you could do is zero it out
@hiredman: I see, I've got a collection of items and I want to group them by date. I guess I should use clj-date or something.
@currentoor: could always group by "beginning of day"
current: in that situation I would likely format the dates as string, and set the formatter to do a format like YYYY-MM-DD
i see
I say that, because I have done that in the past, typically for one off report generating kinds of things, so it may be hacky and not fast enough for some situations
@hiredman: is there a faster way?
@tcrayford: when you say beginning of day do you mean something like what @hiredman is saying?
if you can use jodatime instead of java.util.Date, I think joda time has a single method call to turn a date in to a data at the start of the day
hey @kamuela, this is a topic of interest to me- I concur that Clojure has minimal syntax, in a literal sense- if forms without then or else tokens; Clojure's binding and destructuring syntax; the existence of data literals, etc. That is a major strength, though it raises the learning curve for those coming from more syntactically rich languages, and who want to read Clojure with fluency. Takes more practice to be able to read it without the extra syntactic clues. That said, I would not concur with the therefore. The implied definition of a DSL is that the visual structure of the code- particularly the containment relationship- carries semantically useful information. My experience is that containment is of very limited semantic value when it comes to application components, and relatedly that most DSLs- e.g. macro-based custom syntax- are poor solutions to the problem they are aimed at solving. When one has a containment relationship, best to just represent it with data. Don't waste code on that problem. And just write functions that operate on data. That's simplest and best.
thanks!