This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-12-16
Channels
- # bangalore-clj (8)
- # beginners (78)
- # boot (68)
- # cljs-dev (32)
- # cljsrn (43)
- # clojars (2)
- # clojure (147)
- # clojure-italy (4)
- # clojure-nl (2)
- # clojure-quebec (1)
- # clojure-russia (19)
- # clojure-spec (17)
- # clojure-uk (25)
- # clojurescript (98)
- # clr (2)
- # core-async (14)
- # cursive (5)
- # datascript (1)
- # datomic (23)
- # emacs (4)
- # hoplon (8)
- # jobs (4)
- # kekkonen (1)
- # lein-figwheel (9)
- # off-topic (2)
- # om (2)
- # om-next (9)
- # onyx (4)
- # planck (2)
- # re-frame (14)
- # ring-swagger (3)
- # untangled (18)
Is there a way to automatically require a bunch of namespaces in a library without having to enumerate them? (I’m trying to reflectively enumerate all of the available nses.
Not really. Clojure doesn't really have a notion of the namespaces in a library, because it all gets mashed into the classpath.
and you could potentially enumerate all files on the classpath and filter them by name to try and find the logical contents of some ns subtree
Maybe by looking at the classpath for the JARs on the path and then enumerating those by hand... that would probably be your best shot but assumes that you're working only in a packaged context.
I’m a little confused by clojure.tools.namespace; the docstring says it’s not about JARs, but there’s e.g. clojure.tools.namespace.find/sources-in-jar
At work we have a Boot task that looks at all the source code in a bunch of folders and figures out, given a specified starting folder, which folders need to be on the classpath for that code, based on the network of namespace requires.
@hiredman can tell you more about it -- he wrote it. I'd have to go digging through the build.boot
file to give you more details.
@seancorfield hm. I’m trying to load all the ns’es in amazonica, though
So I might be able to enumerate from the classpath; but they’re not necessarily filesystem paths
You can read entries from a JAR and locate namespaces that way easily enough. Hmm, let me link you some code.
https://github.com/framework-one/fw1-clj/blob/master/src/framework/one.clj#L415-L453 This finds namespaces based on a regex inside JAR files on the classpath
(pay no attention to anything else in the file -- it's an interesting but ultimately failed thought experiment)
I might look at generating a manifest at build time using tools.namespace and then use that to load everything up in "production"
The idea behind that code was that it could find files / namespaces on the classpath both in source file form and inside JARs
@seancorfield Thanks!
@seancorfield FYI, I just did this:
(defn ^:private amazonica-ns?
[ns-sym]
(str/starts-with? (name ns-sym) "amazonica.aws."))
(->> (cp/classpath)
(find-ns/find-namespaces)
(filter amazonica-ns?))
Involves two new dependencies: clojure.{java.classpath,tools.namespace}Sweet!
This is one of the things that always amazes me about Clojure: some of the tools are so simple and yet so powerful!
Hello, all. Has anybody had success with using the CIDER debug mode in Spacemacs? I can't seem to make it work.
@pawandubey please provide more details
@rmuslimov I am jacked in to the REPL, and if I do cider-debug-defun-at-point
I expect CIDER to instrument the defun but instead it just evaluates it and I can't use the usual n, i etc key bindings.
Nevermind, solved:D
Oh, I was being a doofus and not executing the form after calling debug-defun-at-point.
I was reading the clojure.core.specs
definition for defn
and noticed that the multi-arity version also accepts an optional attribute map as the last argument (as well as the second/third alongside doc-string)
the last optinal attr-map seems totally unecessary since you can just have the same information in the earlier position
i need to prune nils and empty maps,vectors etc from a lot of stuff. as a helper i wrote a predicate like that:
(defn safe-empty? [a]
(if (coll? a)
(empty? a)
(nil? a)))
is there maybe a nicer way of expressing that? more idiomatic or in core something i have missed?@karol.adamiec not-empty
will nil empty collections as well as work with nil
. So you could do (complement not-empty)
or just (keep not-empty your-coll)
will not empty work on a non sequable?
that if coll check is for that, cause empty? throws on longs
yep, throws as well
but i might be able to sprinkle that in at the creation moment
so should be fine 🙂, then i just prune nil?
thanks @rauh
Is there a version of juxt
which executes immediately? I can't see anything, wanted something less ugly than ((juxt) x)
don't think so
[(f1 x) (f2 x) (f3 x)]
In the previous snippet how come eval can use config in the repl but not when the code is compiled in a jar ?
it's probably being evaluated in a different namespace
(binding [*ns* (the-ns 'my-ns)] (eval ...))
would fix that
@luxbock: re your question above on the extra meta map in defn - I was not aware that existed till I wrote the spec and I asked Rich. The idea was that meta can get long and can obscure the meat of the function so this gives you the option of sticking it at the end.
that's how I've used it
hello everyone, I’m using the component library from Stuart Sierra, but I’m not sure how to model a system with 2 instances of the same component, any idea?
There is a #component room, but briefly: your system can have multiple instances of the same component registered under different names.
@donaldball thanks, I’ll try
@alexmiller: thanks that's interesting
anyone using the fs library chmod function ? it works in the repl but not in the jar for me and I wonder why
@karol.adamiec if you need something like empty-val? which als works on keywords and numbers i made this little helper for that
(defmulti empty-val? class)
(defmethod empty-val? :default [v] (empty? v))
(defmethod empty-val? Keyword [_] false)
(defmethod empty-val? Number [_] false)
(defmethod empty-val? Boolean [_] false)
(defmethod empty-val? Collection [c] (empty? c))
(defmethod empty-val? String [s] (empty? s))
Hi all, is it possible/reasonable to use clojure.spec for webforms data validation/coercion?
I need some help debugging some async code. I am working on an async web crawler (this is my first Clojure project) https://github.com/pawandubey/crawljer/blob/master/src/crawljer/core.clj
Ah, damn.
My Clojure knowledge is less than a week old. I am yet to explore transducers past their punch line.
@jr wouldn't the desired effect also be achieved by wrapping the map with doall
?
that will force realization but generally you want to avoid map if you don't want to accumulate the results
I saw that doseq
returns a nil
which is kind of not what I want /
Cool. I will try that out and see how it goes.
@pawandubey you can also do doall
or dorun
if you dont care about results (maybe other way around)
I actually decide whether to continue reading from the channel based on what the map returns in the function which wraps the go-loop
.
not sure about performance wise doall
vs mapv
vs into
(defn read-urls
[]
(async/go-loop []
(when read-url
(recur))))
I just check to see if read-url
returns a truthy value to continue with the go-loop.
read-url
calls add-urls-to-chan
as its last form which actually has the map
call.
how about (doall (pmap ...
(if you dont have anything else running on the server) 😄
i guess not really what you want for a lib
I have to say I don't completely grok the effects of the lazy behavior of map
when called in conjunction with other forms.
it doesnt work well with script (process that end when they think they are finished)
(->> (Clojure.string/split-lines log)
(map #(clojure.string/split % #","))
(map reverse)
(group-by first)
(reduce-kv #(assoc %1 %2 %3)) {})
I hope it will have that appropriate metadata since I’m generating it via classpath and find-namespaces
hmm, anyone thinking on writing a Clojure wrapper for http://mxnet.io ?
Anyone know a good way to turn a multilevel hashmap into a string or JSON and preserve the keywords when deserializing?
nvm got it: clojure.walk/keywordize-keys
I’m having a tough time tying to create my own tagged value.
(ns com.walmartlabs.postmaster.address
"Mailbox address data type."
(:import ( Writer)))
(defrecord Address [path mailbox-id])
(defmethod print-method Address
[addr ^Writer writer]
(.write writer
(str "#postmaster/address "
(pr-str [(:path addr) (:mailbox-id addr)]))))
(defn parse-tagged
"Invoked by EDN reader to convert tagged value into an Address.
The value should be a vector of two: a string path, and a second
value, often an UUID, to identify the specific mailbox at the path."
[value]
(apply ->Address value))
But the result in 1.9 and 1.8 is the same:
Clojure 1.9.0-alpha14
nREPL server started on port 59185 on host 127.0.0.1 -
*data-readers*
=> #:postmaster{address #'com.walmartlabs.postmaster.address/parse-tagged}
(require '[clojure.edn :as edn])
=> nil
(edn/read-string "#postmaster/address [:path :id]")
RuntimeException No reader function for tag postmaster/address clojure.lang.EdnReader$TaggedReader.readTagged (EdnReader.java:784)
Debugging gets us to EdnReader line 778, and the valyue is not present in RT.DEFAULT_DATA_READERS.
data_readers.clj:
{postmaster/address com.walmartlabs.postmaster.address/parse-tagged}
edn/read-string doesn't use data-readers if I recall, you ahve to manually pass them in
Then what’s the point of data_readers.clj ; I though that was to seed RT.DEFAULT_DATA_READERS.
From *data-readers*
doc:
Reader tags without namespace qualifiers are reserved for
Clojure. Default reader tags are defined in
clojure.core/default-data-readers but may be overridden in
data_readers.clj or by rebinding this Var.
data_readers.clj does work with the regular reader by default, it is just the edn reader you have to pass them in to
default-data-readers is the built in list of readers clojure ships with (inst and uuid), data-readers is user added readers
Ok then:
(read-string "#postmaster/address [:a :b]")
java.lang.IllegalStateException: Attempting to call unbound fn: #'com.walmartlabs.postmaster.address/parse-tagged
Loading src/com/walmartlabs/postmaster/address.clj... done
(read-string "#postmaster/address [:a :b]")
=> #postmaster/address[:a :b]
… you just have to load the namespace explicitly before attempting to read it.usually better to just ask
there's also a dedicated room for that I believe
Ah, thanks. I am trying to use the test lib, but am apparently missing something. Here's the code:
I think that's normal
The is
statement results in:
clojure.lang.Compiler$CompilerException: java.langRuntimeException: Unable to resulve symbol: is in this context, compiling ...
(ns test (:require [clojure.test :refer [is]]))
should fix that
it means that's the only thing you're "importing"
a more general thing is (:require [clojure.test :as t])
and then you can use t/is
and t/deftest
and everything else in clojure.test
that way
you can mix the two together too, to taste
justinr, here's a pretty thorough rundown on importing/namespaces http://www.braveclojure.com/organization/