Fork me on GitHub
#clojure
<
2016-08-26
>
fenak02:08:30

is it common to have functions for a single element and a list or usually you just explicitly map thought stuff..?

fenak02:08:07

sometimes i feel i’m always creating for example a “do_x” function and a “do_xs” that just maps with the first one

fenak02:08:16

and maybe is not very idiomatic..

cptully02:08:34

I am just beginning to learn Clojure but fining it very interesting.

d-t-w03:08:11

@fenak stuart sierra's "do's and don'ts" covered your question briefly: https://stuartsierra.com/2015/08/10/clojure-donts-redundant-map

fenak03:08:09

@d-t-w awesome! i just refactored to remove this kind of stuff… good thing i was already feeling towards this.. i feel i’m improving. 😄

d-t-w03:08:45

happy days mate, sierra's posts are generally pretty good at covering idioms like thata

fenak03:08:50

yeah, i didn’t know him.. after 10 years of OOP, i’m still getting a grasp on the functional way of doing things

d-t-w04:08:05

I worked with Java predominantly from 97-12, Clojure since. It's still fun and I keep on learning so..

michael.heuberger04:08:21

hello folks - i wonder if dereferencing atoms in let blocks is a good idea?

michael.heuberger04:08:32

or should they be better dereferenced further down in the code?

hans05:08:32

that entirely depends on your code. do you always need the latest value, or do you need one consistent value? generally speaking, though, passing around atoms makes your code depend on external state and thus harder to test and reason about, so it is better to dereference early and pass on values if your application allows that.

hans05:08:39

i generally like to confine atoms and not expose them in the call chain, but i've seen other people write non-functional code in clojure by passing around atoms and be happy with that, so who am i to judge? 🙂

michael.heuberger05:08:16

hmmmm, is there a rule or an official recommendation when to deref in a let block and when not to?

seancorfield05:08:07

I doubt there are any "official" recommendations about that. But I'd say trying to keep state localized if possible is just good hygiene.

seancorfield05:08:14

TL;DR: don't use mutable state 😸

kosecki08:08:41

Hi folks, months ago I found a very nice site with clojure oss projects, indexed code etc. It has great search feature. I can find it anymore...does anyone know what was this site ?

martinklepsch11:08:55

so schema.core/both got deprecated by schema.core/conditional — can anyone give an example of how to construct a composite schema like (s/both s/Str (s/pred seq)) using conditional?

viesti12:08:06

hmm, having problems with reading large result set with clojure.java.jdbc

dpsutton13:08:33

I need to stick a ping pong keep alive heartbeat on a websocket connection. My naive implementation is the following

slipset13:08:53

use timeout

dpsutton13:08:36

like this? I saw the documentation before asking and I was thinking it was going to close my long-running channel

dpsutton13:08:41

but now i see that was me misreading it

dpsutton13:08:29

thanks slipset. exactly what i needed

wgfm13:08:00

Hello there, I’m having a bit of trouble reading a big dataset using postgres. I want to stream the data, so I can process it bit by bit. My data is sorted on a particular key, and I’m using partition-by to dispatch bits to a different part of the application. Problem is, it seems like the driver wants to pull the entire dataset into memory first, before starting to process it, and I’m running out of heap space quickly. I’ve started out with HugSQL (it started as a Luminus project), but that looked like a dead end. At this point, I’m trying to write a solution using clojure.java.jdbc, turning off autocommit and defining a fetch-size. All to no avail. I even tried using an async channel to push rows to in :row-fn, and closing the channel in :result-set-fn, but that solution looks way too convoluted to me. Can anybody shed some wisdom on this? I feel like I’m zoomed in too much at the moment.

slipset13:08:20

I’m curios as to how you’re going about this, since I guess you will need to keep your connection to the database open until the whole result-set is exhausted.

slipset13:08:28

Do you have som example code?

flipmokid13:08:50

Hi, this is probably a simple one. I'm trying to work with the Couchbase Java SDK in clojure and I'm having difficulties with one of the methods I'm trying to translate, RawJsonDocument doc = bucket.get("document_id", RawJsonDocument.class);. Would anyone be able to advise on the best way of doing the RawJsonDocument.class in Clojure. So far I've tried RawJsonDocument/class and (.class RawJsonDocument) but none have seemed to work

slipset13:08:15

(class (RawJsonDocument.))

flipmokid13:08:43

Thanks for that but does it expect a a no arg constructor in that case?

slipset13:08:54

which seems to be somewhat equivalent to (Class/forName “foo.bar.baz.RawJsonDocument”)

flipmokid13:08:56

Oh, let me try that

dpsutton14:08:56

when using jdbc with microsoft sql server, we were having success using [com.microsoft/sqljdbc4 "3.0"]on ubuntu 14.04. We just upgraded to 16.04 and now we are getting reports that there are no suitable drivers

dpsutton14:08:03

does anyone now if the new version 3.0 might not work any longer for us? It just sucks because the sqljdbc4 4.0 isn't distributed easily

idiomancy14:08:57

is there an import equivelent of the ns aliasing functionality? i.e.:

:refer [x] :as {x preferred-alias}
but for imports?

idiomancy14:08:52

something like

(:import  (com.badlogic.gdx ApplicationListener Input$Keys Gdx :as {Input$Keys Keys}))

idiomancy14:08:54

@stuartsierra huh. Well, thanks anyway. Seems odd, considering you could accomplish it by wrapping the body of the namespace in a let statement.

idiomancy14:08:04

weird that theres no macro equivelant.

idiomancy14:08:38

Now that I think about it, its weird that ns doesnt just have a :let option

Lambda/Sierra14:08:10

@flipmokid The Clojure equivalent of Java SomeClassName.class is just SomeClassName

Lambda/Sierra14:08:45

@idiomancy Namespaces do define a lexical scope. Each top-level expression in a file is compiled separately.

flipmokid14:08:47

@stuartsierra Thanks Stuart, I just found that out myself now too. Much appreciated!

Lambda/Sierra14:08:14

you're welcome

idiomancy14:08:48

alright, one more question. What is the clojure preferred idiom for shadowing a builtin variable name? For instance, to avoid in confusion in python, if I wanted to label a var as "dict" I would instead name that var "dict_" because a trailing underscore is the preferred convention in python for shadowing builtin names

dpsutton14:08:10

ECL license question. I'm basically forking someone's repo and then changing quite a lot. I put an acknowledgement in my readme and maintain the ECL license on my project. Is this in compliance with the license?

idiomancy14:08:26

Unfortunately, the only clojure idiom for the same thing has been to give it a more terse, less userfriendly name. i.e. kwd instead of keyword

dpsutton14:08:32

whoops ECL = EPL

luxbock14:08:45

@idiomancy I tend to use kw*

Lambda/Sierra14:08:55

@idiomancy There's no single convention. Abbreviations are most common, followed by athing.

idiomancy14:08:30

whats that latter one? athing?

Lambda/Sierra14:08:45

As in "a thing" where thing is a built-in symbol.

idiomancy14:08:19

err, so just prepending the letter a?

Lambda/Sierra14:08:29

Yes. It's not common, but I see it.

idiomancy14:08:49

haha, okay cool. Thanks @luxbock, thanks @stuartsierra

Lambda/Sierra14:08:51

There are conventions for certain types of arguments: f for function, coll for collection, s for sequence, m for map.

Lambda/Sierra14:08:05

k and v for key and value, respectively.

idiomancy14:08:36

single letter var names can go for a walk on a short one.

dpsutton14:08:08

here's the naming conventions from bbatsov

idiomancy14:08:54

guh. I think we took some of the bad with the good coming from lisp

idiomancy14:08:02

but, i shall say no more

idiomancy14:08:07

i dont think its a popular sentiment

dpsutton14:08:12

there are some single letter conventions, but as function arguments and in small body functions

idiomancy14:08:13

fair enough, either way, thanks for the help!

shader16:08:24

has anyone else run into this error while running lein repl or cider? Reflection warning, clojure/core/memoize.clj:72:23 - reference to field cache can't be resolved.

shader16:08:55

it didn't actually prevent the repl from running though

dpsutton16:08:16

looks like it popus up anytime you have warn on reflection set to true and you are using core.memoize

shader17:08:18

@dpsutton it looks like that should have been resolved two years ago though?

stbgz19:08:53

hey all what should be the expected result of this

(name (keyword  "”))

jr19:08:38

name splits a keyword on “/“

stbgz19:08:03

yeah that was surprinsing to me, in any case how can I read the value name of a keyword that conatins / and :

stbgz19:08:01

do it manually I suppouse

Alex Miller (Clojure team)19:08:03

(name (keyword nil “”))

Alex Miller (Clojure team)19:08:22

might be better to be explicit with the nil namespace in this case

Lambda/Sierra20:08:53

Just don't do that.

quoll20:08:30

I always enjoyed using the keyword function to create keywords that can’t be generated in source (just to be obtuse)

quoll20:08:41

coincidentally, I had a use-case for just such a thing last night (though it was a symbol, not a keyword)

credulous21:08:26

Has anybody accessed a Mongodb store? I’m trying to construct a query against an ISODate field, and I can’t get any records.

(let [{ :keys [conn db]} (mg/connect-via-uri server-uri)
       coll "card_actions"
       from (f/unparse (f/formatters :date-time) (t/epoch))
       actions (mc/find-maps db coll {:timestamp {"$gt" {"$date" from}}})
       ]
   (prn (first actions))
   (reset! card_actions actions)
   (mg/disconnect conn)) 

credulous21:08:57

Using the Monger lib and clj-time. Should return all records, but I get an empty result.

credulous21:08:18

If I replace the {: timestamp … } bit with an empty map, I get all the records.

credulous21:08:10

I’ve tried variations on the query, including {“$gt” from}, {“$gt” {“$isodate” from } } and other stuff I don’t remember.

hagmonk21:08:27

I've an existing Java class that I want to make behave like a map … is this a case of using extend-type? If so how do I find what protocols are used behind map?

hiredman22:08:05

you can't really do that

hiredman22:08:09

the basic map interfaces are java interfaces, and you cannot make a class extend an interface after the fact

hagmonk22:08:31

I thought these extend- functions boiled down to creating clojure functions that switched implementations based on the "this" argument

hiredman22:08:45

those work with protocols

hiredman22:08:28

the map stuff all bottoms out on java interfaces like ILookup

hiredman22:08:05

https://github.com/arohner/clj-wallhack/blob/master/src/wall/hack.clj#L38-L55 creates a new object that implements ILookup for fields on the original object

hagmonk22:08:06

oh, so it never runs through the logic that would dispatch it to the right place

hiredman22:08:21

there no right place

arohner22:08:44

hagmonk if the clojure persistent collections were re-written in terms of protocols, you could use extend-, but that stuff predates protocols, so its written in terms of java interfaces for now

hagmonk22:08:58

I think I finally get it now, with no protocols something like "keys" is just a simple function call that flows through to clojure.lang.RT

hagmonk22:08:24

with protocols there's some dynamic dispatch goop

arohner22:08:31

yep. and from RT it often flows to a java interface

hagmonk22:08:32

so … wrap with reify seems like the approach

hagmonk22:08:57

for the record I'm wrapping an IgniteCache object from Apache Ignite

hagmonk22:08:03

which implements the JCache JSR, and I've been pondering whether there's some connection between clojure.core.cache and JCache I could utilize

arohner22:08:14

making an object correctly implement the map interfaces is tricky. I’d recommend using something like mirror

arohner22:08:13

also, just to make sure, why do you want to make it behave like a map?

hagmonk22:08:56

well, IgniteCache really is just a map of sorts. So I'm writing lots of (.get cache "key") rather than (:key cache)

hiredman22:08:08

if it implements java.util.Map you can treat it like a map for reading purposes

hiredman22:08:53

user=> (:a (doto (java.util.HashMap.) (.put :a :b)))
:b
user=> 

hagmonk22:08:14

it implements Iterable and javax.cache.Cache

hagmonk22:08:08

so for instance getting the keys out is currently (let [c (-> cache .iterator iterator-seq)] (map #(.getKey %) c)

hagmonk22:08:16

or something similar

dpsutton22:08:07

he makes it easy to make a new map

dpsutton22:08:21

by just giving it six functions that are what it means to be a map

hagmonk22:08:27

@dpsutton oh sweet, that is very useful

hagmonk22:08:45

that's basically exactly what I need 😄 😄

dpsutton22:08:20

he has a lot of really cool code

dpsutton22:08:04

he's also a ridiculously nice guy if you get the chance to say hello at a conference

hagmonk22:08:28

I'll be at the conj and may owe him a lot of beer by the time I'm done reading through this