This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-02-09
Channels
- # beginners (205)
- # boot (6)
- # cider (22)
- # cljs-dev (41)
- # cljsrn (4)
- # clojure (97)
- # clojure-dev (61)
- # clojure-greece (40)
- # clojure-italy (8)
- # clojure-russia (16)
- # clojure-spec (18)
- # clojure-uk (34)
- # clojurescript (14)
- # community-development (1)
- # cursive (45)
- # datomic (39)
- # fulcro (66)
- # jobs (2)
- # lein-figwheel (1)
- # lumo (9)
- # off-topic (8)
- # parinfer (98)
- # portkey (8)
- # re-frame (81)
- # reagent (54)
- # remote-jobs (17)
- # ring (2)
- # shadow-cljs (217)
- # spacemacs (32)
- # sql (24)
- # test-check (6)
- # unrepl (73)
- # yada (12)
I have logs of @bronsa's fine rant.... I should get those hosted somewhere. Yet another project. edit: https://www.arrdem.com/logs/Clojurians/%23clojure-dev/%23clojure-dev-2018-02-02.log maybe some file coding issues....
Is there a better way to write this:
(defn foo [& rst]
(into (vec (drop-last rst))
(last rst)))
(foo 1 2 [:a :b :c])
How do we make transit serialize java arrays?
throws Caused by java.lang.Exception Not supported: [Ljava.lang.String;@6117ccdd AbstractEmitter.java: 183 com.cognitect.transit.impl.AbstractEmitter/marshalTop JsonEmitter.java: 28 com.cognitect.transit.impl.JsonEmitter/emit WriterFactory.java: 126 com.cognitect.transit.impl.WriterFactory$1/write transit.clj: 149 cognitect.transit/write transit.clj: 146 cognitect.transit/write transit.clj: 14 jett.argus-compute.transit/data->output-stream
@qqq apply vector
(apply vector 1 2 [:a :b :c])
@seancorfield: right, that works great, but becomes messy when I try to refactor it into afunction
(defn foo [& rst] (apply apply vector rst))
apply
is sort of the inverse of &
@seancorfield: for some reason, I had this incorrect psychological barrier, thinking that apply
was a MACRO, when, in reality, it's a function, so yeah, of course (apply apply vector ...) is valid
does clojure (outside of specialized matrix routiens) have a transpose operator? input = vector of M elems, each elem = vector of N elems output = vector of N elems, each elem = vector of M elems
@qqq (->> vec-of-vecs (apply map vector))
@robert-stuttaford:
1. I can't believe (apply map vector ...)
does transpose
2. even more impressive, after getting over step 1, is that
`(apply map vector
[(range 10000)
(range 10000 20000)])` didn't cause a stack overflow of some sorts (i.e. I expected the 10000 args to apply would screw things up)
actually, I should have tested:
(apply map vector
(for [i (range 1000)]
[i (* 2 i)]))
but that works too w/o overflownot much magic in Clojure, but this certainly bloody feels like it đ
So this works pretty well:
(defn- unique-id-gen
"Generates a sequence of unique identifiers seeded with ids sequence"
[ids]
(apply concat
(iterate (fn [xs]
(for [x xs, y ids]
(str x y)))
(map str ids))))
(take 20 (unique-id-gen ["a" "b"]))
Hi, I want to read all files directory like: /<myproj>/resources/some_dir/ ⌠from within an uberjar.
i can get it working with normal file operations but that doesnât work when i make my app an uberjar
doh. i just realized how to do it:
(-> "somedir/under/resources/"
io/resource
io/file
file-seq )
@kah0ona It is possible to ask classloader about resources, but it's not very simple: https://github.com/Deraen/ring-cljsjs/blob/master/src/ring/middleware/cljsjs.clj#L22-L31
.getResources
returns the list of jar files in classpath which contain the given path, then one needs to go through the jar file contents to check for matching entries
https://github.com/JoelSanchez/ventas/blob/dev/src/clj/ventas/utils/jar.clj
list-resources
will get you a list of the resources in the current jar, you can just slurp
them if you want
@kah0ona @joelsanchez Not sure, but I think running-jar
probably only works when running from uberjar, ring-cljsjs
code should work for both for dev and uberjar
in dev you can just read the files from /resources
@tord: is clj-chess a clojure wrapper of uci? I'm looking for a lib in clojure that can just wrap/interact with stockfish
100-most-used-clojure-expressions file not found with 404 error. http://lispcast.com/files/clojure-source-files.zip Do you guys have this file which include 100 most used clojure expression? I found this page but it is not available now with 404 error.
@foxlog in case you're after the top-most used functions look here https://gist.github.com/reborg/f7068568ff27d2b6b8f3cb5c439e3839
@foxlog hey there! you can download it here: https://www.dropbox.com/s/1gfmzs63qgs56vq/clojure-source-files.zip?dl=0
How many programming languages , should a senior programmer know?
At least 1
lol. ok. Just curious what is the best way to do functional tests within clojure?
Can anyone provide any suggestions in how to enable clojure.data.xml/emit-str
to not raise ExceptionInfo Auto-generating prefixes is not supported for content-qnames. Please declare all URIs used in content qnames. clojure.core/ex-info (core.clj:4617)
when specified xml contains namespaces? I've tried specifying them such as
(xml/emit-str the-xml {:xmlns/gh ""
:xmlns/gs ""
:xmlns/os ""
:xmlns/xsi ""
:xmlns ""})
but that generates a IllegalArgumentException No value supplied for key: {:xmlns/gh "", :xmlns/gs "", :xmlns/os "", :xmlns/xsi "", :xmlns ""} clojure.lang.PersistentHashMap.create (PersistentHashMap.java:77)
https://github.com/clojure/data.xml/blob/master/src/main/clojure/clojure/data/xml.clj#L143-L147
I must admit I'd focused on the readme with
(emit-str (element (qname "" "title")
{:xmlns/foo ""}
and I'd missed the paren thinking :xmlns was an arg for emit-str, not element. However, as I say, trying with options results in the Auto-generating prefixes is not supported for content-qname
Sorry, without
So, I load an xml document up that has several namespaces. Load it into a zipper, make a simple string change to one element's content. If I keep the zipper pointing to this element, or any parent upto, but not including the root element where the namespaces are applied, I can emit-str on that element. As soon as I point the zipper one element up to include the namespaces, I get the previously mentioned error.
Maybe a simple demo would help!
We wrote an article on Clojure Debugging. Feedback, both good and bad, is welcome: https://cambium.consulting/articles/2018/2/8/the-power-of-clojure-debugging?utm_source=slack_clojurians&utm_campaign=clojure
Might be worth posting this to #announcements for more exposure and easier finding later.
> Whilst important and and related, this post wonât cover the following: > > * Setting up logging frameworks Damn! i understand why not, but iâm still disappointed đ
@danielglauser you might also find this interesting - itâs a library I wrote for capturing data at runtime and instead of putting it in an atom to inspect in a repl immediately, putting it in a transit formatted file so that you can debug from another repl or use it in a unit test https://github.com/noisesmith/poirot
also works from cljs
Thanks @noisesmith, Iâll check it out.
In the repl, how do I auto reload and run deftests when files change?
I tried requiring the code in lein-test-refresh
but itâs in a plugin, so it canât be required in a repl(?)
@aaron51 if you use cider, you can enable cider-auto-test-mode
on the test buffer you want to automatically reload; other development environments might have something similar.
If you don't want to use a command line feature, you might look into something like https://github.com/weavejester/lein-auto ?
Thanks @tanzoniteblack I will give this a shot!
Is code in a plugin (like lein-auto
) accessible from the repl? I couldnât require a namespace that was in lein-test-refresh
(it is listed in :plugins
in project.clj)
no, plugins are not meant to be accessible from your project repl
some plugins are accessable from a repl; but I believe that particular plugin is designed to be use standalone from the command line (i.e. in addition to your repl, you'd kick off lein auto test
in another terminal)
from a repl you can run (clojure.tools.namespace/refresh)
and (clojure.test/run-all-tests)
, and hypothetically you could reload files automatically on change (but some might find that disruptive)
the IDE approach would probably easier and more customizable then a lein plugin
@tanzoniteblack some plugins add dependencies to your project, but the plugin itself still isnât in your project, if it was your project would also have to include leiningen itself
@noisesmith you are absolutely correct. But from a user standpoint that difference is just semantics đ
@tanzoniteblack @noisesmith Thank you, this is helpful!
@aaron51 the clojure.tools.namespace readme has some good examples of how to hook its refresh into an app that needs some sort of initialized state at runtime (eg. http server, database connections) and I suspect the reason that thereâs no easy to find auto-reloader is that most people wouldntâ want their http server and db etc. restarted every time they touch a file https://github.com/clojure/tools.namespace
@aaron51 Iâd be careful with automatically refreshing namespaces on file changes with your repl. I think youâll find yourself blowing away state you might be interacting with. This is pretty much why I havenât done work to have lein-test-refresh be callable from a repl.
@jakemcc Understood! So when we use lein-test-refresh itâll run separate from the repl
Short question: what does (fn [a b] (+ a b))
do under the hood?
When I try to dynamically generate a function which coes
a :: int, b :: int -> (+ a b) :: int
I end up either:
1. creating a static class, so it's
(.... some work to generate bytecode ....)
(someClass/myPlus ...)
2. or some method of a class, so I have to call it via
(.go (.... code taht generates class on the fly) 2 3)
Yet, Clojure's fn makes it possible to do:
((fn [a b] (+ a b)) 2 3)
what is going o nwith fn
?
fn creates a new class
Clojure 1.9.0
(ins)user=> (class (fn [a b] (+ a b)))
user$eval11$fn__146
(ins)user=> (class (fn [a b] (+ a b)))
user$eval149$fn__150
in clojure, anything we call a âfunctionâ is an object which implements clojure.lang.IFn
which implements a few methods, importantly applyTo and invoke
@qqq you might find this informative
user=> ((reify clojure.lang.IFn (invoke [this] "HI")))
"HI"
when you put something in parens, clojureâs compiler looks for how to apropriately call it, including checking if it implements IFn
which might help this error message (which I know youâve seen before) make more sense
user=> (1)
ClassCastException java.lang.Long cannot be cast to clojure.lang.IFn user/eval157 (NO_SOURCE_FILE:4)
Always Be Compiling
@qqq I donât know if this addresses your question about âstatic classâ but
(ins)user=> (defn foo [x] (fn bar [y] (+ x y)))
#'user/foo
(ins)user=> (class (foo 1))
user$foo$bar__159
(ins)user=> (class (foo 2))
user$foo$bar__159
- each invocation of foo returns an instance of bar - the difference is that each one has its own binding for x(though I forget if x is directly a field on bar, or if bar internally has some env slot that contains x - most of the time this shouldnât matter)
@noisesmith: this is very helpful, and I think is enough for me to make it work; thanks!
@noisesmith thatâs interesting. can i assume cljs takes an analogous approach?
@lee.justin.m iirc in cljs they can directly use the js function type, instead of needing a special type for functions
since js actually has first class functions that arenât properties of objects natively
right
perhaps clojure implementation would look different if java.util.function.Function etc. came out sooner(?)
sadly the link to the .java file in that article rotted
I tried googling but found nothing promising