This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-12-10
Channels
- # adventofcode (99)
- # architecture (10)
- # bangalore-clj (1)
- # beginners (65)
- # boot (9)
- # cider (78)
- # clojure (87)
- # clojure-austin (1)
- # clojure-brasil (13)
- # clojure-dev (14)
- # clojure-gamedev (3)
- # clojure-greece (2)
- # clojure-italy (2)
- # clojure-russia (18)
- # clojure-spec (26)
- # clojure-uk (15)
- # clojurescript (62)
- # core-logic (1)
- # cursive (1)
- # datomic (27)
- # emacs (17)
- # fulcro (2)
- # off-topic (44)
- # onyx (25)
- # perun (139)
- # re-frame (40)
- # reitit (2)
- # ring (4)
- # rum (2)
- # shadow-cljs (1)
- # slack-help (14)
- # unrepl (18)
Is there a standard way of storing a Directed Acyclic Graph in an Entity-Attribute-Value store ?
an adjacency list would be a simple way to do it
do you store the child list as a single vector, and when you add/del one child, overwrite the entire vector ?
that's an implementation decision, the totally denormalized version would be to make each child relation a separate entry
I think
hello every one, I'm starting to learn clojure (my first real functional language) after doing some functional JS
do you recomend any sql abstractions to use in my project with postgres?
I saw korma, but looks like it is abandoned, and I didn't like the yesql and hugsql approach
@matheusashton I'd recommend HoneySQL which lets you compose query fragments, on top of clojure.java.jdbc
which is the Clojure Contrib library for JDBC operations.
Also @matheusashton since you're new to Clojure and interested in SQL, I'll recommend the #beginners and #sql channels.
Is there a clojure tool that will take a codebase, and show me all defns / defs taht are not used? It can assume I'm not doing something weird via string->symbol->resolve-in-ns
Yagni.
Yes, boot-check
runs Yagni
@konanki.sivaram Use :plugins [[lein-gorilla "0.4.0"]]
instead of :plugins [lein-gorilla "0.4.0"]
How do people feel about doing things like http requests inside of dosync
, for example?
I find myself in a situation where I am receiving many (kafka) messages asynchronously, any of which triggers a particular http call. But I only want to make that call once.
So, I receive the message, dosync
to assoc something under a key and trigger a request only if that key doesn’t exist yet
Hmmm, how do I avoid the race condition here: deref
to see if key exists, if not dosync
to add key and then (at some point) trigger request
Multiple threads could deref
and see the missing key, both add the key and trigger request, unless those are somehow a single transaction
I guess in a single dosync
it can check the key and add it in, no need for a separate deref
generic question. Say I’m building a library and in the default namespace I need an instance of a parser. I will need this parser for every call into the library. I could have a (def parser ...)
directly in the main namespace of the library, but for some fuzzy reason this makes me feel slightly dirty and I would feel more pure with lets say a memoized function returning the parser. Opinions? Is it ok and good style to just (def
things or is it indeed somehow better to keep things in functions? One difference I see is that the def gets potentially ’unnecessarily` evaluated on load. The user of my lib might elect to not call any functions in my namespace etc...
@mbjarland Could use https://github.com/stuartsierra/component to avoid re-defining global variables on load.
That's what was recommended to me instead of global atoms
cloc dumps ttl lines, ttl white space, ttl comments is there some other tool that will dump ttl + also summaries for each file ?
or use https://github.com/Aaronepower/tokei, much much faster
@U3L6TFEJF: cloc --by-file
is awesome; thanks!
i.e. I want a table of four columns: file name, comments, whitespace, line-count // though two clumns of just filename and line-count is fine, if it's better than wc -l
I do that. The repl starts and works for some time and then it stops working. Now I don’t seem to have that problem.
Good Morning Everybody 🙂
besides fn -> \lambda
is there a standard set of "prettify these clojure keyword" setup ?
Sorry guys but I still cannot understand what those cmd line tool just released https://clojure.org/reference/deps_and_cli here are for. What gap did I have that they are trying to fill?
they are for people who have never tried clojure and want something minimal to fire it up
@alexmiller pointed me to https://clojure.org/guides/deps_and_cli. But if I have leiningen, what do i need those for?
you don't, and it's not for you
it's for people who haven't used clojure and want a simple way to fire up a clojure repl. Or people who want something ligher weight / more targetted than lein or boot for running a repl.
I also get the impression that they provide an official solution from the clojure team for launching a clojure repl. Previously it was sufficiently simple to not matter.
in the past we could use clojure.jar for that, clojure.jar no longer runs standalone because of clojure.spec.alpha
right, python just runs as a standalone command
because it's not part of clojure.core, it's a separate artifact
so you need to construct a classpath with at least three artifacts to make it work iirc
you can't just 'stuff it in the *.jar" ? I thought jars were just zips/tar files and you could throw stuff into it
deps.alpha knows how to resolve deps, that is why it is there
it helps construct a classpath and download jars that you might need
but unlike lein or boot it isn't for packaging or deploying and doesn't have tooling for plugins
yes, you could use mvn for that, but then you need an mvn command for running clojure
and mvn is also a packaging and plugin and deployment tool like leiningen or boot are
Thanks @noisesmith I was afraid I am missing something here.
is there a builtin for (magic [f1 f2 f3 f4] [x1 x2 x3 x4]) => [(f1 x1) (f2 x2) (f3 x3) (f4 x4)] }
the closest thing would be (map #(%1 %2) ...)
(def a-z
(mapv int->char (range (char->int \a) (inc (char->int \z)))))
(def letters-lower "abcdefghijklmnopqrstuvwxyz")
besides listing out the answer, is there a way to make the def of a-z shorter ?Is there something like (binding [*ns* 'afsdfsd] ::a)
but that works?
('work' -> result in :afsdfsd/a
)
yeah, guessed so... thanks for the confirmation! useful coming from tools.analyzer author 🙂
hey everyone, how can I lowercase the keys in map? 😄 I have the following:
{:CurrentGame 1
:Score 30}
and I want to lowercase the keywordsthis response comes from the server as json and when it is converted from json using clj-http, that’s how it shows up
solved it like this
(defn lower-case-keys [result]
(if (map? result)
(into {}
(for [[k v] result]
[(keyword (lower-case (name k))) v]))
(map lower-case-keys result)))
(reduce-kv #(assoc %1 (keyword (lower-case ( name %2))) %3) {} json-response) something this
personally I like to use my own syntax sugar
(defn map-keys [f m]
(->> m
(map (fn [[k v]]
[(f k) v]))
(into {})))
(defn map-vals [f m]
(->> m
(map (fn [[k v]]
[k (f v)]))
(into {})))
@bravilogy with specter: (transform [MAP-KEYS NAME] clojure.string/lower-case m)
also does not change the type of the map and much higher performance than other approaches, especially for small maps
you can also do it with transducers and avoid creating the intermediate seq like this @bravilogy
(defn lower-case-keys [m]
(into {} (map (fn [[k v]] [(-> k name lower-case keyword) v])) m))