This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-05-29
Channels
- # architecture (2)
- # bangalore-clj (2)
- # beginners (177)
- # boot (1)
- # cider (36)
- # clara (15)
- # cljs-dev (30)
- # cljs-experience (6)
- # cljsrn (7)
- # clojure (94)
- # clojure-argentina (2)
- # clojure-brasil (1)
- # clojure-dusseldorf (6)
- # clojure-greece (1)
- # clojure-italy (18)
- # clojure-norway (4)
- # clojure-quebec (1)
- # clojure-russia (28)
- # clojure-sg (3)
- # clojure-spec (12)
- # clojure-turkiye (1)
- # clojure-uk (12)
- # clojurescript (169)
- # code-reviews (4)
- # community-development (2)
- # core-async (6)
- # core-matrix (6)
- # cursive (35)
- # datomic (18)
- # devcards (4)
- # euroclojure (1)
- # hoplon (2)
- # keechma (4)
- # klipse (2)
- # leiningen (1)
- # luminus (16)
- # mount (1)
- # off-topic (34)
- # om (31)
- # pedestal (6)
- # re-frame (14)
- # reagent (33)
- # specter (4)
- # uncomplicate (8)
- # unrepl (15)
- # untangled (24)
- # yada (25)
Is there any standard way operate with namespaced maps?
My use case: I have a state and I use namespaces to keep (almost) all stuff on first level
So I have, for example {:app/tab :page.foo.tab/first :app/page :page/foo :api/foo [:bar1 :bar2] :auth/token "123"}
Sometimes, I want to dissoc
all app
atributes from this map.
Today, I'm doing this (->> (keys state) (group-by namespace) :app (#(apply dissoc state %)))
@souenzzo with specter (setval [MAP-KEYS (selected? NAMESPACE #(= "app" %))] NONE data)
i'd guess at least 10x faster as well
Hi all, I've been trying to use a macro to wrap a Java builder, as explained in an SO post here: https://stackoverflow.com/questions/37503316/creating-a-clojure-macro-that-uses-a-string-to-call-a-java-function After reading it, it makes sense to just use interop as its expressive enough, but thought that it would be helpful to have the builder class itself wrapped in a function so a doc string could be associated with it for easy reference at the REPL. Is this a reasonable thing to do, or am I being unclojurey? 🙂
'Morning. A quick question. We are developing a project which has 1 backend (ring and compojure-api) and 3 different interfaces (re-frame). Now we would like to split this huge project (and the git repositories) in 4 different subprojects. Any advice or thought about how we should proceed?
@mdallastella, my contrarian advice: keep everything in a single repository. Unless you're hitting git's limits (you shouldn't at this scale), splitting repos adds hardly any value and prevents useful hacks (like having a common library accessible from all subprojects, just by adding it to the source-paths)
Also in case of cross-cutting refactorings (e.g. renaming a keyword), you have the whole change in an atomic commit, not spread across multiple histories.
@pesterhazy yeah, we cosidered to keep one projects and one of the pros were the common libraries
I just have some doubts when we will deploy the entire project (and it's maintenance)... but we'll see
the alternative is to push individual libs to a private maven repository and use manual versioning to keep things up to date
@mdallastella as someone building a private Maven repo service, I have a slightly contrarian view to @pesterhazy 🙂, but I can't really disagree too much with him here. At Day8 we've considered a monorepo several times as we have a lot of shared library code between different projects, but it has worked better for us to split it out into separate projects. This is more a function of our org structure and release process though
Question: Is there a way to force tools.namespace to always reload a namespace? I'm using hugsql, and I want to reload my hugsql definitions when the SQL file changes. I'm don't think I can do that with tools.namespace, so the next best thing is to always reload the namespace that defines the hugsql functions
Is there a better way to rewrite this?
(def directions
{:north [dec identity]
:east [identity inc]
:south [inc identity]
:west [identity dec]})
(defn move
"Transform the coordinate to the given cardinal direction"
[direction coord]
(vec
(let [funcs (direction directions)]
(for [[f v] (zipmap funcs coord)]
(f v)))))
andrea.crotti:
(defn move [dir [y x]] (let [[y-f x-f] (directions dir)] [(y-f y) (x-f x)]))
which is for example used as
(move :north [0 0]) => [-1 0]
I kind of think that for could be removed but not really sure how
(defn move
[direction [x y :as coord]]
(let [[x-func y-func] (direction directions)]
[(x-func x) (y-func y)]))
mm nice, but it now depends on the fact that there are only 2 dimensions
would it be possible to keep it more agnostic about the number of dimensions?
@andrea.crotti - Not without a for
or other loop. 😄
I think mapv reads nicer than using vec, for and zipmap… but yes you need something like that
changing it slightly from @tatut this works perfectly well
(def directions
{:north [dec identity]
:east [identity inc]
:south [inc identity]
:west [identity dec]})
(defn move
"Transform the coordinate to the given cardinal direction"
[direction coord]
(mapv
(fn [func c] (func c)) (direction directions) coord))
thanks!
another thing I'm not too sure is using keywords as functions implicitly
I mean maybe (get directions direction)
is more explicit in this case?
but probably it's fine, if it's common practice in Clojure anyway
Apologies if this comes up over and over, but the (supposedly required) name field on the Clojure contributor agreement is not a fillable field. Anyone else run into this?
That name field was an eyebrow-raising looks-like-a-bug for me, too.
+user=> (.length (java.io.File. "/home/justin/.profile"))
972
noisesmith: file.Files has a much faster method to do this. but you probably don't need to care
@danp Wrapping the builder class in a function could be nice, but builders are often times specific. Writing a doc for it would be good for that use case, but not all. Sometimes the java interop is so easy that wrapping it doesnt give much of an advantage. Perhaps the thing you are using builder for should be documented.
@noisesmith : a related questino: do I need to put that in an with-open ? when/when-not do file type resourceds need to be put in a with-open ?
it doesn't open the file
with-open is for InputStream, or other similar resources that have a .close method
does antyghin in http://clojure.java.io/ need with-open ? or is it only when I do stuff like (java.io.ByteArrayOLutputStream. ...) ?
it's for things that keep a socket or file descriptor and use it over multiple calls; since you have a limited set of descriptors you can use and it's a good idea to close them explicitly
but the main thing I'd check is if the object you created has a .close method - because with-open can't really help you if there's no .close
@qqq it might but I wouldn't count on it
I guess we could make an experiment and find out
I just noticed $project_dir/target/classes
is by default on the classpath, at least when running with Leiningen... anyone know what's adding that?
e.g. in a vanilla lein new empty-project
; lein repl
; (filter #(re-find #"target" %) (map str (.getURLs (java.lang.ClassLoader/getSystemClassLoader))))
I just spent at least an hour figuring out why tools.namespace
was refusing to refresh
without errors. Turned out it was getting messed up because of AOT compiled classes from a previous uberjar build
I don't see a reason why target/classes
should be on the class path when running a dev/repl environment, but maybe there's a reason?
byte[]
is really a low level data structure, I would probably only use it if either some library requires byte[]
as input, or if I'm trying to write very specific optimized code
I assume ByteBuffer
really just wrapes a byte[]
array, but it implements a bunch of higher level operations so you don't have to
@hswick cheers, the Java library is documented. I'll see how I go and if I'm constantly referring back to the javadoc, I'll write a function around the class and doc string it :)
Bumping this just in case... I'm trying to figure out what is adding target/classes
to the classpath... seems to be on there by default, not sure if it's Leiningen, Clojure or Java that's doing it
if anyone can evaluate (filter #(re-find #"target" %) (map str (.getURLs (java.lang.ClassLoader/getSystemClassLoader))))
in any boot project
do you have an invocation that I can quickly test? I really don't know how to use boot... how do I generate an app and start a repl?
I'm suspecting it's leiningen... when running java -jar ep31.jar clojure.main
from an uberjar it's not there
(defn classloader-hierarchy
"Returns a seq of classloaders, with the tip of the hierarchy first.
Uses the current thread context ClassLoader as the tip ClassLoader
if one is not provided."
([] (classloader-hierarchy (.. Thread currentThread getContextClassLoader)))
([tip]
(->> tip
(iterate #(.getParent %))
(take-while boolean))))
lein uses pomegranate for classloader management. is it possible that this is the offender right here?
not there on boot, so it seems to be Leiningen. Thanks for the pointer, that gives me something to look into.
i cloned that project and tried to add a failing test if applicable and I don't know how to jack into a project without a project file but only a pom file
i guess you have to maven install your deps manually but i don't have maven on work computer as this is a .NET shop
hello, does anyone know how to run a project via leiningen in non-headless mode? I want an icon etc to appear on my desktop
I tried passing "-Djava.awt.headless=false"
to :jvm-opts
in project.clj
but it had no effect
@stathissideris I think you need a ^:replace on the :jvm-opts value for that to work
the replace metadata tells it to replace the opts, not just add yours to the list
@noisesmith thanks, I’ll give it a try!
still no luck, but maybe I’m missing something
are you looking at the args generated (eg. via ps ax)
is there a library which provides extension macros to clojure.test providing things like is-not
and contains?
?
honestly I just do that as (is (not ...)) and (is (contains? ...)) - I've never seen a library with such things
yeah that’s what i’ve been doing too.
@benjamingramlich - Midje provides a variety of sugar for tests. Not sure about is-not
specifically though.
https://github.com/marick/Midje
i’m familiar with Midje. I guess what I want is more something like AssertJ that works seamlessly with clojure.test