Fork me on GitHub
#clojure
<
2016-03-01
>
jtackett01:03:20

Hey does anyone know how to write the opportunity contact role in salesforce API?

jimmy03:03:55

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}

akjetma03:03:20

apply merge

jimmy04:03:21

@akjetma: thanks for suggestion. I have solved the problem using reduce

venantius06:03:05

is it possible to use Sente to create, e.g. an RTM slack bot?

venantius06:03:12

(in Clojure, not ClojureScript?)

akjetma07:03:38

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.

spacepluk09:03:27

is there any way to redefine .?

bronsa09:03:57

it's a special form, hard-coded in the compier

spacepluk09:03:47

that's so sad, not even as a scoped binding let-like?

bronsa09:03:25

well, you can use it as a value

bronsa09:03:46

no, not even like that

spacepluk09:03:18

I'm trying to get this to work: (.)(.) 😄

spacepluk09:03:14

maybe with a macro :?

bronsa09:03:53

well, if you have your macro interpret that expression, then you'll be able to do that

bronsa09:03:47

(defmacro x [& body]) and you'll be able to write anything you like inside (x ..)

spacepluk09:03:45

I see, I think it serves the purpose for my stupid joke 😄

spacepluk09:03:27

so the special forms are somehow "hardcoded" in eval's implementation?

jimmy10:03:10

hi guys, can we pass custom function in (cond->). For example: (cond-> {} predicate #(if ...)

jimmy10:03:03

hmm it seems that we have as->

joost-diepenmaat13:03:31

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?

joost-diepenmaat13:03:58

assuming normally down-stream components shut down if their up-stream channel closes

spacepluk13:03:23

sorry I thought it was funny

spacepluk13:03:42

didn't mean to offend anybody

Lambda/Sierra13:03:34

@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.

Lambda/Sierra13:03:05

When I use both together, I tend to manage the closing of channels and go blocks independently from Component stop.

tolitius13:03:05

@spacepluk: you mean something like:

boot.user=> (def . 42)
#'boot.user/.
boot.user=> .
42
?

tolitius13:03:51

@spacepluk: ah.. scrolled up a bit, I see

spacepluk13:03:11

@tolitius hmm interesting it doesn't work when you put a function in the var and try to call it

spacepluk13:03:14

good to know

bronsa13:03:10

special forms are only resolved in function position

tolitius13:03:40

@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/*

asolovyov13:03:48

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. simple_smile

joost-diepenmaat13:03:31

@stuartsierra: thanks I’ll give that a try

jcromartie14:03:01

is there a function like concat but which keeps the first arg’s type?

jcromartie14:03:08

like, concat but return a vector

jcromartie14:03:10

that returns a lazy seq

jcromartie14:03:38

something like (f [1 2] [3 4]) => [1 2 3 4]

eraserhd15:03:21

I’d like to make a REST API server, with URLs modeled around resources, the way rails “suggests” one does.

eraserhd15:03:43

This is clearly something that is easy enough to code with ring. I was wondering if there’s a library that already does this.

eraserhd15:03:52

With attributes backed by a database.

eraserhd15:03:00

s/attributes/entities/

jstew15:03:18

@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.

eraserhd15:03:42

@jstew: Hrmm. Liberator looks really interesting.

ordnungswidrig15:03:15

eraserhd: if you need any help with liberator or yada, there are channels for those libs.

jonahbenton16:03:32

@asolovyov: that clojure timestamp is a count of seconds since jan 1 1970.

jonahbenton16:03:43

in your riemann debug logs you may have every event but you probably have duplicated timestamps for clojure events?

wei16:03:35

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))

Chris O’Donnell16:03:03

Is there a reason you're not using clojure.core/fn??

asolovyov16:03:16

@jonahbenton: I can, of course - there are many events happening in the same second

nonrecursive16:03:09

@eraserhd: I made library which handles route creation for rails-style rest resources with liberator https://github.com/flyingmachine/liberator-unbound

nonrecursive16:03:31

it’s kind of funky and I might not have explained it well in the readme but it might do what you want

nonrecursive16:03:38

the examples at the bottom of the readme show how you can generate the routes

josh.freckleton17:03:21

simple question, how do I quote the deref symbol @, so it stays @ instead of clojure.core/deref

eraserhd17:03:18

@nonrecursive: I quick-read the README, and am not sure I grok it. I’ll spend more time on it later.

eraserhd17:03:41

It looks like I might need to be familiar with liberator first.

nonrecursive17:03:24

@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 simple_smile

josh.freckleton18:03:52

@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?

eraserhd18:03:48

I’m not sure your assumption is correct, though, since the reader expands @

eraserhd18:03:44

Yup, it’s expanded, even when quoted.

nkraft18:03:28

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.

josh.freckleton18:03:57

@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?

nonrecursive19:03:03

@josh.freckleton: I’m pretty sure that’s correct

josh.freckleton19:03:51

@nonrecursive: (= '(clojure.core/deref myatom) '(@myatom)) => false in my repl, should this not be true then?

nonrecursive19:03:37

so if you just do ’(@myatom) it expands to ((clojure.core/deref myatom))

nonrecursive19:03:00

try (= '(clojure.core/deref myatom) '@myatom)

josh.freckleton19:03:44

ahh, genius. I've gotta look out for how macros expand, that's bit me before too. Thanks so much @nonrecursive!

eraserhd19:03:12

@josh.freckleton: @ is a “reader macro”, which is different from a normal macro, FYI.

Alex Miller (Clojure team)19:03:28

reader macros expand at read time, before compile/macro-expansion time

josh.freckleton19:03:55

@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?

josh.freckleton19:03:55

ok, I'll look it up to learn more, ya the #() macro bit me once before when I was trying to thread it with (->)

josh.freckleton19:03:16

I didn't realize it was a read time thing though, that's really cool to know we have that!

Alex Miller (Clojure team)19:03:33

reader macros are not user-extensible though - they are fixed in the reader (which is different than other Lisps)

hans19:03:11

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.

josh.freckleton19:03:35

@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 😉

Alex Miller (Clojure team)19:03:13

of course there is the #= reader macro escape hatch but you have to be in double secret Clojure club to use that

hans19:03:45

uh oh. where can i read about that?

Alex Miller (Clojure team)19:03:58

are you in double secret Clojure club?

hans19:03:08

for the purpose of this discussion, i am

Alex Miller (Clojure team)19:03:09

it's just eval (at read time)

hans19:03:30

wow, that is disappointing. i'll not make that claim again.

hiredman19:03:31

well, not exactly eval

josh.freckleton19:03:49

ohhh, haha , i was googling furiously to find it

josh.freckleton21:03:15

@nonrecursive: Awesome, that's a fantastic reference, thanks!

jcromartie21:03:34

I need forcat

jcromartie21:03:57

(defmacro forcat [binding body] `(apply concat (for binding body)))

jcromartie21:03:08

or maybe reduce would be smarter

hiredman21:03:36

for can do that

hiredman21:03:58

yeah, just add another binding

jcromartie21:03:11

ah, of course!

robertkuhar21:03:13

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]]

jcromartie21:03:24

thanks @hiredman I should have thought of that

hiredman21:03:03

robertkuhar: what is the problem you are seeing?

robertkuhar21:03:52

The first ring of hell begins with some Arity Exception FAIL (Arity Exception...ultimately instaparse)

robertkuhar21:03:24

As I baby step my way out of that...I end up at a point where everything runs, but the swagger page 500 errors

robertkuhar21:03:28

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

jcromartie21:03:19

geez, this is not how semantic versioning is supposed to work… 😞

robertkuhar21:03:25

please excuse me...I'm new to this

jcromartie21:03:35

upgrading to 1.x should not break things that worked in 1.y

hiredman21:03:53

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

jcromartie21:03:53

do you have any AOT output?

robertkuhar21:03:55

sad, but true...here is the first ring of hell

jcromartie21:03:05

have you tried “lein clean"

robertkuhar21:03:14

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)

robertkuhar21:03:20

it goes on for a while

robertkuhar21:03:30

thats the thing caused by the instaparse no good

jcromartie21:03:30

yes, Clojure added a clojure.core/update function

robertkuhar21:03:10

I have tried

lein clean

jcromartie21:03:12

do you know where the dependency on Instaparse is coming from?

robertkuhar21:03:05

Yes...compojure:1.3.1 which is there due to metrosin/compojure-api:0.17.0

robertkuhar21:03:50

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

jcromartie21:03:54

looks like Compojure 1.3.3 fixed the incompatibility between Instaparse and Clojure 1.7

jcromartie21:03:32

interesting… Instaparse was depending on some internal Clojure details and not the public API

robertkuhar21:03:02

OK. So whats the magic I use to figure out which metosin/compojure-api brings in compojure 1.3.3?

jcromartie21:03:06

so this is a case where Clojure adhered to semantic versioning, but using an undocumented API caused problems… interesting!

jcromartie21:03:13

lein deps :tree > deps.txt

robertkuhar21:03:18

again, excuse my ignorance...I'm new to this

jcromartie21:03:27

no problem at all, this is hard stuff

jcromartie21:03:29

dependency hell

jcromartie21:03:46

at least Leiningen, in my experience, is better than dependency management in Ruby or other languages I have worked in

jcromartie21:03:22

lein deps :tree will output the full dependency tree so you can see what’s requiring what

robertkuhar21:03:10

yeah...I'm there compojure-api is bringing it in

robertkuhar21:03:15

[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"]

robertkuhar21:03:42

But I don't know what I need to do to that to get it to version up compojure to 1.3.3

Chris O’Donnell21:03:37

@robertkuhar: It looks like compojure-api 0.19.3 is the first version to use compojure 1.3.3

robertkuhar21:03:52

Ah...OK. I've been there

robertkuhar21:03:12

Thats the point where I had everything working...except the BLoody swagger page

Chris O’Donnell22:03:01

Yeah, it looks like 0.19.3 pulls in ring-swagger 0.19.4, which pulls in ring-swagger-ui 2.0.24

robertkuhar22:03:27

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

jcromartie22:03:58

what if you explicitly require a higher version of compojure?

jcromartie22:03:05

I’m not sure how that works

robertkuhar22:03:19

yeah...I've not tried that

jcromartie22:03:55

see what happens if you require the latest compojure in your project’s deps

robertkuhar22:03:04

I'll beat on this a little longer on my end. Thanks

jcromartie22:03:02

I’m assuming you can’t upgrade to a recent version of compojure-api because you want the Swagger 1.2 support?

robertkuhar22:03:26

If I could figure out how to get out of Swagger 1.2, that is the better path out

robertkuhar22:03:24

and come back with what's broken at that point

robertkuhar22:03:41

in any event, I won't bug you guys until I get better information

Kamuela22:03:33

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?

Kamuela22:03:16

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

Kamuela22:03:48

Almost when you feel like you're "programming" you're already using a language ill suited to the task

hiredman22:03:07

kamuela: the no syntax thing is something I see repeated about different lisps here and there, and I think it is silly

hiredman22:03:19

lisps definitely have syntax

hiredman22:03:01

it tends to be very uniform at the base level

hiredman22:03:55

and every macro you write, effectively has its own syntax, but it tends to be grounded in that base level

Kamuela22:03:36

Well the base level is function

hiredman22:03:30

function application

hiredman22:03:06

creating a function relies of different bits of syntax depending on how you want to do it

hiredman22:03:32

(fn ...) #(...) (defn ...)

hiredman22:03:43

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

hiredman22:03:12

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

hiredman23:03:05

a claim I see repeated in similar places to "lisp as no syntax" is "in lisp you write the ast directlly"

hiredman23:03:01

having spent some time with the clojure compiler and written some toy compilers, that claim also strikes me as bunk

hiredman23:03:44

asts are much richer in explicit information than lisp code generally

currentoor23:03:20

How do I drop the time part of a datetime instance?

currentoor23:03:27

so only the date from (java.util.Date.)

hiredman23:03:46

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

currentoor23:03:53

@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.

tcrayford23:03:34

@currentoor: could always group by "beginning of day"

hiredman23:03:56

current: in that situation I would likely format the dates as string, and set the formatter to do a format like YYYY-MM-DD

hiredman23:03:13

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

currentoor23:03:40

@hiredman: is there a faster way?

hiredman23:03:59

I dunno, it has never come up for me

hiredman23:03:46

cjl-date may have some nice functions for it (I've never used it)

currentoor23:03:52

@tcrayford: when you say beginning of day do you mean something like what @hiredman is saying?

hiredman23:03:30

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

tcrayford23:03:34

somewhat. clj-time has a helper function for time -> beginning of day

tcrayford23:03:42

and yeah, don't use java.util.Date

tcrayford23:03:50

clj-time/jodatime are far, far superior

swizzard23:03:06

hey, is there not an #enlive channel?

jonahbenton23:03:22

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.