This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2015-11-24
Channels
- # admin-announcements (25)
- # beginners (132)
- # boot (89)
- # cider (26)
- # clara (12)
- # cljs-dev (10)
- # cljsrn (11)
- # clojure (151)
- # clojure-germany (8)
- # clojure-russia (1)
- # clojurescript (137)
- # cursive (33)
- # datavis (28)
- # datomic (3)
- # devcards (8)
- # hoplon (5)
- # immutant (11)
- # jobs (4)
- # ldnclj (58)
- # lein-figwheel (7)
- # off-topic (95)
- # om (114)
- # onyx (91)
- # parinfer (38)
- # portland-or (1)
- # re-frame (26)
- # reagent (1)
@davebryand: I don’t know about 'best practice’, but it seems overkill in that app, just because the conn won’t really change. In that case, just use (let [conn (init-conn]), and have init-conn just be (d/connect (:datomic-uri (read-config))
. My best practice these days is to use Component
(I don’t really like the term Best Practice), but I recommend Component for most everything now
Thanks @arohner — is there a good example app out there that you can recommend that I look at to see how things get wired up with Component?
@davebryand: this is a pretty decent answer: http://stackoverflow.com/questions/29070883/how-to-use-stuart-sierras-component-library-in-clojure
awesome, thanks!
I’m looking at an issue with Instaparse right now, where Cursive will incorrectly print its failure values.
This is because Instaparse redefines print-method
, which means that nREPL returns formatted text in its val
field which holds the result of the evaluation.
Cursive (perhaps incorrectly) expects something that looks more or less like a Clojure object in there.
hey guys. I'm writing a desktop app in clojure(script) and want to give the user a option to specify the modules he wants to use
in my python version, I generate a tree of directories based on the modules the user enters and fetch a specific python file in that directory
everything is lazy loaded. If the user doesn't use a module, it's not even loaded by the app and everything in that modules folder is untouched
I want to do something similar in clojurescript but feel like this would get a little bit more difficult. Is a lazy-loaded approach even the right idea here or should I just compile everything together and ignore certain things based on a settings file?
has anyone used kerodon? I am trying to figure out if there is an easy way to check the content type of the response
@dvcrn: you may be better asking this in the #C03S1L9DN channel But it sounds to me like you want modules. This link may help: https://rasterize.io/blog/cljs-dynamic-module-loading.html
@jonpither: @bensu made a thing called asterion that might help
also http://www.clojureatlas.com/ but that’s pretty old and I’m not sure if it’s supposed to work with codebases outside clojure.core
I'm trying to write some runtime assertions for functions that will be passed in (this is library code). I expect a map like {:some-fn some-fn :other-fn other-fn}
and I want to verify that these functions accept and return the correct types of values. Is there a good way to do this?
@jstew @dm3 both of those would require something to be done when the function is constructed right? But assuming it's just passed in as a normal function, could I use something like test.check to validate inputs/outputs? Or a series of assertions?
@jmmk: You would need to know the structure of the inputs with schema, but at runtime you call validate
Thanks @martinklepsch and @malch for source visualisation recommendations
@jstew @dm3 The options I'm looking at: * I could have macros for creating the functions that would automatically add the schema and run validation * I could just create the schemas and have them available but optional (this one might be easiest) * I could validate them at runtime by testing inputs and outputs (this is the one I'm currently exploring but it sounds like there's not a good way to do it)
so their inputs and outputs need to conform to some shape that you know at the point you store them?
I'd probably try to restrict users to define a function through the given means (e.g. macro)
@jonpither: lein-ns-dep-graph is good
@danielcompton: yeah just tried it - is useful thanks
Hello I want to add multiple entries in an map. How can I achive this? My attempt:
(doseq [n [1 2 3 4 5]]
(let [req-id (clj-wamp.core/new-rand-id)]
(println req-id)
[{} {} (assoc {} req-id ["test" #(fn [] (println "test"))])]))
[
{}
{}
{1212 [„test“ #(fn [] (println „test“))])
{1212 [„test“ #(fn [] (println „test“))])
{1212 [„test“ #(fn [] (println „test“))])
]
I know, the doseq repeats the function and returns nil, so not what I want. But I can’t get the way, how to achive this.
(let [req-id 1212]
(into [{} {}] (map (fn [k] {k ["test" #(fn [] (println "test"))]}) (repeat 3 req-id))))
or even
(let [req-id 1212]
(into [{} {}] (repeat 3 {req-id ["test" #(fn [] (println "test"))]})))
do you folks think Mastering Clojure Macros (http://www.amazon.com/Mastering-Clojure-Macros-Cleaner-Smarter-ebook/dp/B00SW17V7E/ref=mt_kindle) is worth buying?
@agile_geek: @pbostrom THanks. But what if I want the req-id to be different on each time?
yep e.g.
(into [{} {}] (repeat 3 {(rand-int 100) ["test" #(fn [] (println "test"))]}))
let me edit mine, @agile_geek's solution is better anyway
and you could pass an argument for the number of repeats if that needs to vary.
(defn my-collection [n]
(into [{} {}] (repeat n {(rand-int 100) ["test" #(fn [] (println "test"))]})))
@danielgrosse: based on your original question "I want to add multiple entries in an map", are you sure the above is what you want? This creates a separate map for every new random id. maps usually contain multiple keys/values
No, I want to have the entries to extend the third map. And @agile_geek `s solution always generates the same id.
(into [{} {}] (repeat 3 {(rand-int 100) ["test" #(fn [] (println "test"))]}))
=>
[{}
{}
{15 ["test" #object[main$eval18372$fn__18373 0x468cf149 "main$eval18372$fn__18373@468cf149"]]}
{15 ["test" #object[main$eval18372$fn__18373 0x468cf149 "main$eval18372$fn__18373@468cf149"]]}
{15 ["test" #object[main$eval18372$fn__18373 0x468cf149 "main$eval18372$fn__18373@468cf149"]]}]
(into [{} {}] (repeat 3 {(rand-int 100) ["test" #(fn [] (println "test"))]}))
=>
[{}
{}
{29 ["test" #object[main$eval18380$fn__18381 0x35b685b4 "main$eval18380$fn__18381@35b685b4"]]}
{29 ["test" #object[main$eval18380$fn__18381 0x35b685b4 "main$eval18380$fn__18381@35b685b4"]]}
{29 ["test" #object[main$eval18380$fn__18381 0x35b685b4 "main$eval18380$fn__18381@35b685b4"]]}]
(into [{} {}] (repeat 3 {(rand-int 100) ["test" #(fn [] (println "test"))]}))
=>
[{}
{}
{64 ["test" #object[main$eval18388$fn__18389 0x24587d3a "main$eval18388$fn__18389@24587d3a"]]}
{64 ["test" #object[main$eval18388$fn__18389 0x24587d3a "main$eval18388$fn__18389@24587d3a"]]}
{64 ["test" #object[main$eval18388$fn__18389 0x24587d3a "main$eval18388$fn__18389@24587d3a"]]}]
Would appreciate some help understanding where map->Datomic
is defined as used in this line:
(defn new-datomic-db [uri]
(map->Datomic {:uri uri}))
https://github.com/danielsz/system/blob/master/src/system/components/datomic.clj#L15@danielgrosse: sorry. try this
(into [{} {}] (map (fn [n] {n ["test" #(fn [] (println "test"))]}) (take 3 (repeatedly #(rand-int 100)))))
I forgot Clojure will memoize the rand-int function
little more succinctly
(into [{} {}]
(map (fn [n] {n ["test" #(fn [] (println "test"))]})
(repeatedly 3 #(rand-int 100))))
as repeatedly takes an int argument which is the number of repetitions
@davebryand: it's done by the defrecord macro: https://github.com/clojure/clojure/blob/clojure-1.7.0/src/clj/clojure/core_deftype.clj#L378
brilliant! Thank you @pbostrom
any macro specialist who can help me figure out what must be placed after the other part here : https://www.refheap.com/112028
@nooga: maybe (map :name (:members (type-reflect <you record class>)))
- but you'll have to substract with a field-less dummy record to only get the declared fieldnames
thanks @birdspider, I’ll tinker with this
@roelof well, I assume that the value of others will be everything but the first 2 elements of the form, thus you drop 2
I think it has to do with changes in the stack due to direct linking, interacting with my use of anonymous functions in test helper macros.
I have a patch for that, noticed it in a report from @andy.fingerhut
using this pattern within my tests:
(defmacro check-query
"The extra function wrapper is a stopgap to avoid java's method bytecode size too large limit..."
[spec]
`((fn [] (let [spec# (test-spec ~spec)]
(swap! test-report-state conj spec#)
(is (expected-es-query spec#))))))
the helper macro's purpose was to keep line numbers in the first place, without me having to write is
everywhere
whoops, there's an extra pprint require in there for no reason, but you get the picture.
Can anyone explain to me what this recepient means : (defprotocol Award (present [this recipient])) and why not a variable name as name
I do the clojure koans and try to understand things. This is a chapter about defrecord and deftype
It corresponds to the "thing" implementing that protocol. This may help clear that up: https://clojuredocs.org/clojure.core/defprotocol
It doesn't have to be called "this", but it's required and refers to the thing implementing that interface.
Sorry, I read your question as "being implemented by Award". So you're correct, it's the thing that's implementing your Award. Sorry about the confusion.
Also @andy.fingerhut it should help the case you noted here, https://groups.google.com/d/msg/clojure-dev/xDx3qsjhLVs/mHCxgOZKBwAJ
Though that example uses walk (which is recursive)...there's probably a more minimal case
@ghadi: Updated my tiny test repo with results of trying out your patch, and linked to them from a comment on the ticket http://dev.clojure.org/jira/browse/CLJ-1854. The results look good to me.
I cannot load datomic.api
into my environment, and I'm scratching my head. The thing is, the exception and its message don't give me much information. Does anybody know how to go about troubleshooting this?
Error:
user=> (.printStackTrace *e)
java.lang.NoClassDefFoundError: Could not initialize class datomic.api__init
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:348)
at clojure.lang.RT.loadClassForName(RT.java:2093)
at clojure.lang.RT.load(RT.java:430)
$ find .m2 -iname "*.jar" | grep datomic
.m2/repository/com/datomic/datomic-pro/0.9.5327/datomic-pro-0.9.5327.jar
Why don't we have better diff tools for LISP? For example, suppose I have a large block of logic (an AST) and I add a single line inside it which refers to a func defined in a newly enclosing letfn
block (which refers/uses a few other functions from the same letfn
block). A naive diff tool like the ones supplied by git and GitHub will show a huge block of deleted text and a huge block of added text replacing it (covering the entire scope of the letfn
). I'm sure we can do better than this given the ease with which LISP can be parsed and manipulated.
[Reading a style guide for Elm which aims (among other goals) to minimize diffs led me down this line of thinking-- on the surface, naive diff tools can't do very well with this sort of edit to LISP code but a deeper/semantic diff tool is certainly feasible in LISPs (and perhaps more so) than other langs (yet we still don't see them in widespread use)].
can someone explain to me what present does : (defprotocol Award (present [this recipient]))
@roelof: protocols are similar to Interfaces in OO languages. In your example, present is a function specification (but not an implementation).
a protocol is a group of function signatures
present is one of the function signatures
@roelof: for reference: http://clojure.org/protocols
it takes an instance (named this) and a recipient
yes, it's a parameter to the function
just like (defn present [this recipient])
from a caller's point of view, exactly the same as that
some ways you could create an instance that implements the protocol:
1) use reify to create an anonymous instance (reify Award (present [this recipient] (str "Awarded to " recipient)))
2) use extend-protocol to create a concrete extension (extend-protocol Award String (present [this recipient] (str "Awarded " this " to " recipient)))
then any String can be "presented".
3) supply a protocol definition inside defrecord or deftype (defrecord FamousAward [title] Award (present [this recipient] (str "Awarded " title " to " recipient)))
then (->FamousAward "Best Dad")
It looks as if I missed at least one step in getting set up with datomic. Sorry about the noise.
@johanatan: I don't know if there is a tool specifically for diff'ing Lisp-style languages. There is clojure.data/diff that might help, but it probably isn't as sophisticated as one would like when diff'ing code to find common portions in substructure. 'git diff -w' (-w to ignore whitespace differences) often does better than without the -w
@andy.fingerhut: ahh, nice. Didn't know about -w. Will try that. Looks like there's a big opportunity here for LISPs to stay ahead of the curve.