This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-09-08
Channels
- # aws (21)
- # beginners (62)
- # boot (29)
- # chestnut (1)
- # cider (110)
- # cljs-dev (37)
- # clojure (93)
- # clojure-berlin (1)
- # clojure-dev (10)
- # clojure-greece (4)
- # clojure-italy (5)
- # clojure-new-zealand (1)
- # clojure-spec (6)
- # clojure-uk (46)
- # clojurebridge (1)
- # clojurescript (54)
- # cryogen (1)
- # cursive (22)
- # datomic (72)
- # emacs (2)
- # events (3)
- # flambo (1)
- # hoplon (88)
- # jobs (6)
- # juxt (51)
- # lein-figwheel (1)
- # leiningen (3)
- # lumo (12)
- # mount (4)
- # off-topic (3)
- # onyx (3)
- # pedestal (4)
- # portkey (27)
- # re-frame (13)
- # reagent (1)
- # ring (4)
- # rum (2)
- # uncomplicate (1)
- # unrepl (3)
good point; actually, what is the correct behaviour of (avg ) ? should it be nil? 0? throw exception?
Logically, it should probably be nil. Or throw an exception. But definitely not 0, as that’s a totally valid mean value, e.g. (avg [-2 -1 1 2])
not in core
Hi guys. I am trying to run-all-tests of my lein project in a repl. I'd need to load/require all my test namespaces, so that I could run them with (run-all-tests #"mynamespace.*"). Is there a similar way to load/require all the test namespaces by a project-specific package regex? Thanks
@andras.liter you could create a namespace that requires all the namespaces you want to test
thanks @fmind, I am looking for fast feedback loops for test development with Eclipse, and lein test is incredibly slow (to run on each small change), thus want to have a repl running
in that case, you ca simply create a namespace that loads all the others you want to test
yes, will try that - hoping that listing all test namespaces there & run-all-tests then results in the same outcome as running lein test
in cmdline and on our build server
is there a way to have assoc
stay with array maps even when they grow past size 10 without switching to a third party implementation? i.e. assoc switches to PersistentHashMap from PersistentArrayMap when the maps become large enough (> 10) and I need the map to stay ordered
seems to be the case, so I need the keys I add to the map to stay in the order I add them, which array map does and hash maps doesn't
https://github.com/amalloy/ordered has insertion-ordered maps
i think the array-map to hash-map conversion is just how clojure works, no way around it
maybe I can always transform the map keys and values to sequences and call (apply array-map <seq>)
i.e. take the original map, get keys and values, append a key and a value, call array-map to create a new map
ugly, but should probably work...was hoping there was something less messy than that
@mbjarland have you tried https://github.com/amalloy/ordered ?
Since it’s pure clojure you could just paste the sources you need into your project, no extra dependencies that way
Having some real weird problem in a large-ish project: I removed expectations
code (everything works) and then I removed the dependency and suddenly my uberjar build fails with: java.lang.ClassNotFoundException: cljs.tagged_literals.JSValue
I removed all transitive dependencies from the expectations
dependency via :exclusions
— everything works — once I remove expectations
itself things break
When I create a diff of the lein deps :tree
output before and after removal of expectations
it’s a one line difference (i.e. only expectations itself)
here’s the full stacktrace: https://gist.github.com/martinklepsch/a5c28fbfdc5b7ff65f8edd56a8dbe1f8
Seems that if I add a Clojurescript dependency to my regular build (i.e. not just :dev
) things work. Just wrecks my brain what expectations
has to do with all of that 😄
which is more idiomatic for filtering out nils, (filter identity coll)
or (filter (complement nil?) coll)
?
I realize the material difference if coll contains booleans
actually, maybe (remove nil? coll)
is better
yes, that ^^
This kind of makes me thing I would need to add my src
dir manually, but it seems it’s implicit https://github.com/clojure/brew-install/blob/master/docs/guide-clj.adoc#including-your-source-directory-into-the-classpath
try clj -S
— I see src
listed at the end @ghadi
The default deps.edn includes it now
It's not implicit but you're getting it by the user level defaults
@U064X3EF3 not sure I understand what that means? not implicit but still a default in some way?
It's not implicit because it's not hard coded into the library or the algorithm. You're getting it due to the merge of user level deps.edn and project level deps.edn. And both of those are under your control.
@U064X3EF3 I never created any deps.edn
file though? Is there some default thats used if there is no file?
Probably at ~/.clojure/deps.edn
$ cat ~/.clojure/deps.edn
cat: /Users/martin/.clojure/deps.edn: No such file or directory
$ clj -S
/Users/martin/.m2/repository/org/clojure/clojure/1.8.0/clojure-1.8.0.jar:src
The guide doesn’t seem to mention any default values for when that file does not existIf it doesn't exist, one is created
So it always exists
Do you have the XDG env vars set up? Might be in ~/.config/clojure if so
duh, ok, yeah, I have XDG_CONFIG_HOME set up 🙂
Hi guys, we just had an interesting discovery when working with clojure: we can call functions like clojure.string/replace
throughout our project without explicitly having to require the clojure.string
namespace. I assumed the same would hold true for the entire core lib, so I called clojure.set/intersection
without requiring clojure.set
. This worked in the REPL, but when trying to build an uberjar I get a compilation exception: java.lang.ClassNotFoundException: clojure.set, [...] Exception in thread "main" java.lang.ClassNotFoundException
. To get it working I had to require clojure.set
at the top of my file. Is there a reason why this behaviour differs between different core libs and between REPL/uberjar?
if you refer to the namespace qualified symbol clojure.string/includes?
and the namespace clojure.string has already been loaded (by something else), this is fine.
you should still :require
namespaces explicitly, and not assume that something else loaded them
Yes, this. Right now some namespaces are loaded as a side effect of startup. But that may not always be the case (there are some pending patches that improve startup time by loading less for example)
also, some namespaces might be loaded implicitly because of the internals of your tooling, but hey you have different tooling in dev vs. production so hello bug that only shows up when you deploy
for cljs, you’d encounter a similar bug in case your prod build uses advanced compilation and your dev build does not (which I think is a very normal setting - I encountered it with some template project.clj settings, at least)
cljs.pprint/pprint
was undefined in my prod build, but worked fine in my dev build
once I :require
d it, no problem in either build
Hey fellas! Does anyone happen to know what serialization format nippy
uses? (its the serializer that Carmine uses, which is the library for interacting with redis via clojure)
Its own format. The code is fairly readable and the binary format quite simple. But it s full of custom stuff to support backward compat, compression, pojo serialization etc, I wouldn't advise trying to reverse it in another lang.
I had to share a redis instance that had a good amount of netty specific stuff with an erlang server, l ended up converting all the redis data to something more portable. One alternative is to write a little service that acts as encoder/decoder in clj, it s a bit naive but if it s not a hot path in your app it could work
yeah, so I discovered. You can get Carmine to store it raw though with a little work.
Aaah, ok. So every ns needs to be required explicitly, even when it's in the core lib? The reason I got so far without requiring clojure.string
is probably because it is so common that in most cases one of my dependencies will probably already have required it without me knowing...
we've got other services in Nodejs that have to read values in redis which were stored via clojure
so presumably we have to deserialize it into edn somehow, and then convert it to json
it's most common to alias namespaces @vincentdm ... (:require [clojure.string :as string])
then call (string/replace...)
Yeah, I know, but we have a convention of not aliasing clojure.string to make it more portable when copy-pasting code between files. I guess we better start doing so, because then my IDE (Cursive) will notify me of omitted requires.
noob question, I have two functions which both return a reify implementing a number of protocols, there is a fair amount of code duplication between the implementations of the two reifys, how do you go about sharing code in this scenario? just move things to functions in the enclosing namespace? I realize this question might be too open, but if I at least understand the options, maybe I can make a better choice
in case anyone was wondering, its a nippy specific format. its not language agnostic. I need to find some way to change the serialization that carmine does.
try clj -S
— I see src
listed at the end @ghadi
hi clojure. is there a trick to using gen-class?
Is there a builtin way to go from a java.util.Enumeration to a seq? I have:
(defn enum->seq
[^java.util.Enumeration enum]
(lazy-seq
(when (.hasMoreElements enum) (cons (.nextElement enum) (enum->seq enum)))))
which works fine, but less code is betteri get ClassNotFoundException whenever i try and use a class i've defined elsewhere 😞
(ns model.document (:gen-class :name model.document :implements java.io.Serializable :state "state" :init "init" :constructors {[String String String] []} :methods [[getContent [] String] [getTitle [] String] [getUrl [] String]])) (defn -init [content title url] [[] (atom {:content content :title title :url url})]) (defn- get-field [this k] (@(.state this) k)) (defn getContent [this] (get-field this :content)) (defn getTitle [this] (get-field this :title)) (defn getUrl [this] (get-field this :url))
(ns classification-server.classifier (:require [model.document :refer :all])) (new model.document "my-content" "my-title" "my-url")
how do i do that in leinigin?
@ben.mumford you can provide an :aot key in project.clj, see lein help sample
for a lot more info
excerpt:
;; These namespaces will be AOT-compiled. Needed for gen-class and
;; other Java interop functionality. Put a regex here to compile all
;; namespaces whose names match. If you only need AOT for an uberjar
;; gen-class, put `:aot :all` in the :uberjar profile and see :target-path for
;; how to enable profile-based target isolation.
:aot [org.example.sample]
thanks for the pointer, i'll give that a try