This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-08-26
Channels
- # admin-announcements (1)
- # beginners (12)
- # cider (2)
- # cljs-dev (6)
- # cljsrn (4)
- # clojure (123)
- # clojure-austin (10)
- # clojure-brasil (1)
- # clojure-canada (21)
- # clojure-conj (5)
- # clojure-dev (8)
- # clojure-gamedev (42)
- # clojure-russia (121)
- # clojure-sanfrancisco (2)
- # clojure-spec (25)
- # clojure-uk (36)
- # clojurescript (195)
- # clojutre (3)
- # cursive (43)
- # datomic (6)
- # defnpodcast (2)
- # dirac (14)
- # emacs (2)
- # ethereum (2)
- # events (2)
- # funcool (6)
- # hoplon (76)
- # jobs (1)
- # kekkonen (9)
- # lein-figwheel (1)
- # leiningen (4)
- # mount (6)
- # off-topic (5)
- # om (2)
- # onyx (91)
- # pedestal (2)
- # protorepl (14)
- # re-frame (22)
- # reagent (20)
- # rethinkdb (1)
- # ring (2)
- # schema (3)
- # sfcljs (3)
- # spacemacs (15)
- # specter (12)
- # testing (1)
- # yada (63)
is it common to have functions for a single element and a list or usually you just explicitly map thought stuff..?
sometimes i feel i’m always creating for example a “do_x” function and a “do_xs” that just maps with the first one
@fenak stuart sierra's "do's and don'ts" covered your question briefly: https://stuartsierra.com/2015/08/10/clojure-donts-redundant-map
@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. 😄
happy days mate, sierra's posts are generally pretty good at covering idioms like thata
yeah, i didn’t know him.. after 10 years of OOP, i’m still getting a grasp on the functional way of doing things
I worked with Java predominantly from 97-12, Clojure since. It's still fun and I keep on learning so..
hello folks - i wonder if dereferencing atoms in let blocks is a good idea?
or should they be better dereferenced further down in the code?
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.
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? 🙂
hmmmm, is there a rule or an official recommendation when to deref in a let block and when not to?
I doubt there are any "official" recommendations about that. But I'd say trying to keep state localized if possible is just good hygiene.
The community style guide has very little to say about it https://github.com/bbatsov/clojure-style-guide/blob/master/README.md#mutation
This has some good guidelines too https://rasterize.io/blog/clojure-the-good-parts.html
TL;DR: don't use mutable state 😸
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 ?
@kosecki crossclj?
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
?
I need to stick a ping pong keep alive heartbeat on a websocket connection. My naive implementation is the following
like this? I saw the documentation before asking and I was thinking it was going to close my long-running channel
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.
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.
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
which seems to be somewhat equivalent to (Class/forName “foo.bar.baz.RawJsonDocument”)
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
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
is there an import equivelent of the ns aliasing functionality? i.e.:
:refer [x] :as {x preferred-alias}
but for imports?something like
(:import (com.badlogic.gdx ApplicationListener Input$Keys Gdx :as {Input$Keys Keys}))
@stuartsierra huh. Well, thanks anyway. Seems odd, considering you could accomplish it by wrapping the body of the namespace in a let statement.
@flipmokid The Clojure equivalent of Java SomeClassName.class
is just SomeClassName
@idiomancy Namespaces do define a lexical scope. Each top-level expression in a file is compiled separately.
@stuartsierra Thanks Stuart, I just found that out myself now too. Much appreciated!
you're welcome
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
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?
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
@idiomancy I tend to use kw*
@idiomancy There's no single convention. Abbreviations are most common, followed by athing
.
As in "a thing" where thing
is a built-in symbol.
Yes. It's not common, but I see it.
haha, okay cool. Thanks @luxbock, thanks @stuartsierra
There are conventions for certain types of arguments: f
for function, coll
for collection, s
for sequence, m
for map.
k
and v
for key and value, respectively.
there are some single letter conventions, but as function arguments and in small body functions
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.
looks like it popus up anytime you have warn on reflection set to true and you are using core.memoize
yeah that was surprinsing to me, in any case how can I read the value name of a keyword that conatins / and :
(name (keyword nil “
might be better to be explicit with the nil namespace in this case
Just don't do that.
I always enjoyed using the keyword
function to create keywords that can’t be generated in source (just to be obtuse)
coincidentally, I had a use-case for just such a thing last night (though it was a symbol
, not a keyword)
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))
Using the Monger lib and clj-time. Should return all records, but I get an empty result.
I’ve tried variations on the query, including {“$gt” from}, {“$gt” {“$isodate” from } } and other stuff I don’t remember.
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?
the basic map interfaces are java interfaces, and you cannot make a class extend an interface after the fact
I thought these extend- functions boiled down to creating clojure functions that switched implementations based on the "this" argument
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
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
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
which implements the JCache JSR, and I've been pondering whether there's some connection between clojure.core.cache and JCache I could utilize
making an object correctly implement the map interfaces is tricky. I’d recommend using something like mirror
well, IgniteCache really is just a map of sorts. So I'm writing lots of (.get cache "key")
rather than (:key cache)
so for instance getting the keys out is currently (let [c (-> cache .iterator iterator-seq)] (map #(.getKey %) c)