Fork me on GitHub
#clojure
<
2015-08-11
>
zane08:08:31

Is it just me, or does lein auto not play well with do?

atroche08:08:58

how do you guys feel about using (seq []) instead of (not (empty? []))?

kazuwal08:08:55

which one reads better?

atroche08:08:44

i much prefer the second one, but which is more idiomatic?

borkdude08:08:28

I have isolated my dependency problem I spoke about yesterday. It's here: https://github.com/borkdude/ring-problem

borkdude08:08:49

If anyone can see what is the problem with this project, please shout!

borkdude08:08:09

The error I'm having is: java.lang.ClassNotFoundException: ring.middleware.not-modified, compiling:(matchmaker/api.clj:52:7)

atroche08:08:40

“Please use the idiom (seq x) rather than (not (empty? x))”

kazuwal08:08:54

well i've just learnt something simple_smile

atroche09:08:43

@adebesin: i wonder if it's just for historical / consistency reasons?

atroche09:08:59

and if seq is idiomatic, why does https://clojuredocs.org/clojure.core/not-empty exist?

bensu09:08:18

but you are not requiring the namespace

borkdude09:08:35

@bensu: Thanks. I'll try it

bensu09:08:13

@borkdude: also, make sure one of your ring :dependencies includes it

borkdude09:08:35

That's it. Doh. I didn't even think about it, because it worked in a project where I borrowed this code from.

bensu09:08:35

@borkdude: I'm glad it was that simple simple_smile

kazuwal09:08:38

@atroche: not-empty? will return the collection if true eg (not-empty? [1]) => [1] that's the only difference I can see

kazuwal09:08:21

@atroche: I assume calling seq will return true | false

ragge09:08:28

@adebesin: calling seq will return a seq on the given coll, or nil

kazuwal09:08:30

Then (seq x) rather than (not (empty? x)) makes little sense given you'd want true | false

niwinz09:08:38

@atroche: the most idiomatic way to check if collection is empty is using seq

niwinz09:08:50

(when (seq coll) (do-things))

st09:08:26

@borkdude: the simplest mistakes are sometimes the most difficult to debug...

borkdude09:08:48

@st especially when they accidentally work in some environments

ragge09:08:25

@adebesin: depends on the situation, nil is falsey so works well in logical tests (as @niwinz shows)

ragge09:08:03

@adebesin: pretty good article on nil-punning in clojure: http://www.lispcast.com/nil-punning

pupeno10:08:05

Is there a function to dig down into maps that contain maps to avoid nested gets? something like (get person :name :first-name) ?

agile_geek10:08:40

@pupeno:

(get-in person [:name :first-name])
in your example

hugobessaa11:08:20

hello clojurians simple_smile

hugobessaa11:08:49

I couldn’t find a way to destructure using keys and &

hugobessaa11:08:04

in ES2016 this will be possible:

hugobessaa11:08:31

{a, b, …rest} = {a:1, b:2, c:3, d:4}

hugobessaa11:08:55

any way to do something like this with let?

hugobessaa11:08:27

(let [{:keys [a b] & rest} {:a 1 :b 2 :c 3 :d 4}]) which is invalid

hugobessaa11:08:15

don’t know if here is the best place to get help 😛. If not I can delete these msgs

luxbock11:08:36

what is rest bound to in the ES2016 example?

hugobessaa11:08:57

bound to rest var, an array

hugobessaa11:08:22

it would be better used as let {a, b, …rest} = {a:1, b:2, c:3, d:4}

luxbock11:08:09

so it would contain [3, 4]?

luxbock11:08:09

I think it's not possible in Clojure

hugobessaa11:08:47

I misread docs

hugobessaa11:08:04

it would be bound to rest var, an object

luxbock11:08:03

Clojure allows you to use :as m which would bind the whole map to m

luxbock11:08:34

but m would still contain both :a and :b

hugobessaa11:08:52

this did the trick: (let [{:keys [a b] :as m} {:a 1 :b 2 :c 3 :d 4} m (dissoc m :a :b)] (println m))

hugobessaa11:08:17

clojure
(let [{:keys [a b] :as m} {:a 1 :b 2 :c 3 :d 4} 
       rest (dissoc m :a :b)] (println m))

hugobessaa11:08:25

not sure if mutating m inside let is ok

hugobessaa11:08:03

(edited to avoid mutation)

andre.richards14:08:23

@shamatov I would have found any actual coding, however simple, quite frustrating if I didn't understand some of the ideas behind clojure. I suggest you watch Introduction to Clojure for Java programmers (even if you don't know Java - it doesn't go into Java in any detail AFAIR, more OOP vs FP, and gives good intro to Clojure data structures) Also, I highly recommend Clojure Programming (O'Reilly) . It starts with some Ruby and Java code, then shows the Clojure equivalent. Clojure has very little syntax, which is great when you have a bit more experience, but when starting out, can be a bit daunting, and IMO this book does nice job to show how Clojure is built up of smaller building blocks (e.g. it shows do form, and then other places where do is 'implicately' used, etc). Helped me understand how things fit together.

greywolve15:08:01

does anyone have good examples of a hexagonal architecture / ports and adaptors sort of approach to Clojure? or functional programming in general, how these ideas translate?

pupeno15:08:24

Is there a way to use threading (-> or ->>) when some functions require the passing argument as the first one and some as the second one?

arrdem15:08:47

Pupeno as->

pupeno15:08:24

arrdem: beautiful.

teslanick15:08:25

Woah. I wish I knew about that months ago.

arrdem15:08:49

As or cond threading through multiple conditional bodies is the greatest thing ever.

lvh15:08:28

@atroche: Definitely seq.

martinklepsch15:08:08

Wrote a minimal Clojure client for Airtable (40loc): https://gist.github.com/martinklepsch/302121cdacd6771354c6 — Feedback welcome

hlship16:08:53

@chouser: I tend to go the route of each component has an atom or two for internal state (such as caches or whatnot). But it is concievable that you could have a State component that is simply an Atom containing a hash-map that can then be shared between lots of components.

hlship16:08:22

But then you trade off the optimization of just having a single atom (and perhaps, a single view to mutable application state)

hlship16:08:44

against the need to use more complex keys when reading/modifying the atom's map value.

arrdem16:08:07

is there a good embeddable database here in Clojure land? I'm trying to slap together a simple CRUD service for my own use for organizing papers, tracking contacts and otherwise doing structured document storage and search.

arrdem16:08:10

The simplest thing that could possibly work would seem to be a heap of UUID named EDN objects and a browser.

martinklepsch16:08:45

@arrdem: I guess you care about storing the data yourself right?

arrdem16:08:45

@martinklepsch: I mean there's nothing security sensitive I intend to store here, but yeah being able to maintain local state and synchronize via dropbox or something would be nice.

arrdem16:08:11

I can hammer out a UUID heap in a few minutes but if there's something else compelling I'm happy to look at/hear about it.

gtrak16:08:20

@arrdem: I think for structured document searching, it's going to be hard to beat elasticsearch, but might be overkill.

gtrak16:08:38

I'm enjoying the API though

gtrak16:08:49

in my day job

arrdem16:08:00

yeah I've heard good things about elasticsearch and we're using it in prod here but I haven't had to really mess with it.

gtrak16:08:14

aggregations are super easy to consume in clojure, just some edn and results are a for-comprehension away.

greywolve16:08:06

@arrdem, there's https://github.com/tonsky/datascript, and then you could also use something like h2 (SQL), or neo4j if you are into graph databases 😛

arrdem16:08:04

yeah I think elasticsearch is overkill for this... my data is likely to be sufficiently small that I could probably make a single EDN file work 😛

gtrak16:08:32

you could use straight-lucene then

gtrak16:08:52

I've gotten something to work with this: https://github.com/weavejester/clucy

arrdem16:08:28

gtrak: nice! looks right up the alley I'm after!

zane16:08:21

For web development what are people using to manage their assets (e.g. compile LESS / SCSS, etc)? It seems like there are one-off leiningen plugins for these kinds of tasks, but I'm wondering if people are eschewing all that in favor of using tooling from other languages (Grunt / Gulp / etc).

gtrak16:08:08

@zane: I think #C053K90BR was built for these use-cases and is similar in architecture to gulp

arrdem16:08:48

yeah this is exactly Boot's problem space

zane16:08:52

Was just wondering how common that is relative to other options.

zane16:08:33

I'm really excited about Boot.

gtrak16:08:40

I think it's going to be hard to not rely on npm on some level.

zane16:08:34

Is npm finally the de-facto tool for managing front-end JavaScript packages?

zane16:08:44

(I'm just a dabbler with front-end stuff.)

martinklepsch16:08:50

@arrdem: you could probably make something nice using electron, allows you to access the filesystem properly so you can sync your edn files/client-side db

gtrak16:08:53

the react community is standardizing around npm, babel, and webpack

gtrak16:08:06

so as far as i'm concerned, yes simple_smile

martinklepsch16:08:28

@gtrak: @zane targeting node or browser? I haven’t needed npm myself yet

arrdem16:08:32

@martinklepsch: hum... yes but learning JS/CoffeeScript is probably out of the time budget for this project 😛

arrdem16:08:44

ClojureScript is right out for the same reason...

gtrak16:08:03

@martinklepsch: webpack lets you use npm as a dependency manager but package for browser, same as browserify

gtrak16:08:26

but I think most/all react libs are distributed on npm now

martinklepsch16:08:38

@arrdem: you can easily make electron apps with CLJS

martinklepsch16:08:50

@zane: @gtrak unless you have special needs I’d say you can easily make your way around npm when making cljs stuff

zane16:08:08

@martinklepsch: For this particular project the front-end is in vanilla JavaScript.

zane16:08:39

I investigating doing asset management via leiningen and there be dragons.

gtrak16:08:55

it's getting easier, especially with the recent work letting closure compiler consume other modules, but unfortunately for legacy-code and social reasons I won't be able to avoid npm, coffeescript, bower.

gtrak16:08:21

and if you want to use react js deps, then you need to deal with it somehow,

zane16:08:28

@martinklepsch: No, no I did not. 💖

martinklepsch16:08:17

@gtrak: you mean react plugins/addons type stuff?

gtrak16:08:28

or 3rd party components

gtrak16:08:37

or like immutablejs

gtrak16:08:42

in a hybrid codebase

martinklepsch16:08:20

@gtrak: it’s fairly trivial to make packages with deps.cljs. probably only an option when npm isn’t already being used.

gtrak16:08:01

I should also mention we're transitioning from an ember codebase simple_smile. I think it's nice that we're packaging stuff up for closure/cljs, but there are going to be cases where decent interop is truly necessary, the flexibility to have cljs consume other things, and the reverse.

gtrak16:08:31

if the upfront cost is too high, then it can never get done

martinklepsch16:08:37

Agree, it just sounded a bit like “you’ll need npm” and that didn’t seem right 😛

zane17:08:18

@martinklepsch: The problem I'd be trying to solve is how to avoid having to vendor everything.

zane17:08:39

And for that, it'd be tough to justify re-implmenting everything npm does for you.

arrdem17:08:37

gtrak: bad news, clucy is pretty old and upgrading to latest lucene isn't gonna be trivial 😐

arrdem17:08:05

does this not compile down to a single argument Object[] parameter?

arrdem17:08:53

just trying to understand what the Clojure side interop is gonna look like.

ztellman17:08:16

arrdem: that’s correct

arrdem17:08:44

ztellman: amusingly this seems to be a reflection issue that my recent work would fix...

arrdem17:08:02

due credit to Alan for actually carrying that team

sandbags17:08:08

I just got a pretty weird error from my Compojure app (https://gist.githubusercontent.com/mmower/3e8eb55ba4b5bdb94593/raw/3873ba6c40f93e78383fdd0c892ce38cf72584a9/gistfile1.txt) i’m commenting out code to try and figure out what i broke but I can’t see anything relating to my code in this stacktrace, anyone see anything I am missing?

arohner18:08:53

@sandbags: you need to upgrade instaparse. They were relying on an internal implementation thing in Clojure, broke in 1.7

arohner18:08:19

so, upgrade instaparse, or revert clojure to 1.6

martinklepsch18:08:04

Updating compojure to latest should also work @sandbags

arrdem18:08:43

Okay so it looks like what's happening is that into-array has tag ^"Ljava/lang/Object;" which is strictly correct because anything is an Object however in the method call case I'm interested in it's not sufficient because there are two varargs methods which are more specific than Object so when Clojure emits a reflective method call with an Ljava/lang/Object; there result is a no such method exception. Neat.

shriphani21:08:00

Hi folks. I’ve got a question about compojure-api - does anyone have an example for setting Access-Control-Allow-Origin in my API ?

juhoteperi21:08:40

@shriphani: Should work the same as with regular compojure

shriphani21:08:28

@juhoteperi: I don’t see any ring middleware calls in the defapi macro examples so I am a bit confused.

juhoteperi21:08:10

(defapi app' ...)
(def app (-> app' (wrap-foo-bar)))

shriphani21:08:02

ah that helps thanks simple_smile