This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-10-11
Channels
- # beginners (57)
- # boot (9)
- # clara (9)
- # cljs-dev (12)
- # clojure (98)
- # clojure-boston (1)
- # clojure-dusseldorf (12)
- # clojure-france (1)
- # clojure-greece (1)
- # clojure-spec (41)
- # clojure-uk (86)
- # clojurescript (60)
- # code-art (2)
- # data-science (5)
- # datomic (5)
- # duct (1)
- # fulcro (14)
- # graphql (2)
- # lein-figwheel (4)
- # luminus (1)
- # midje (1)
- # off-topic (19)
- # om (10)
- # onyx (13)
- # pedestal (5)
- # portkey (59)
- # re-frame (31)
- # reagent (1)
- # ring (14)
- # ring-swagger (1)
- # rum (5)
- # shadow-cljs (90)
- # spacemacs (5)
- # specter (47)
- # sql (9)
- # uncomplicate (95)
- # vim (32)
What’s the easiest way to try out the clj
script from brew-install
? https://github.com/clojure/brew-install
I git clone
ed the repo and am not sure where to go from there…
Are you just trying to get a CLJ environment setup?
No. I’m trying to play around w/ @U064X3EF3’s work in brew-install
.
It's in the central tap - just "brew install clojure" for 1.8.0 or "brew install --devel clojure" for 1.9.0-beta1
Yeah, found it thanks to @U065JNAN8. Might be useful to link to it in the brew-install
README: https://github.com/clojure/brew-install/blob/master/README.md
It’s in brew
So brew install clojure
@lewix being able to partipate in this clojurian channel to witness a vibrant, innovative, cooperative, clojure community, is itself a daily blessing 👍
But these aren't run automatically, you have to call instrement
which is in the spec.test namespace I think?
There may be a nice way to enable the s/fdef
checks for a single function. https://clojuredocs.org/clojure.spec/fdef
@blmstrm You may want to try https://github.com/jeaye/orchestra too, it looks pretty great 🙂
@olical What I was hoping to use spec for, even in production, was to avoid alot of validation of incoming data and just define specs for incoming and outgoing values. But the more I read up on it it seems it is not recommended to have it turned on in production.
It's never so much on or off. How I see it: Use fdef all over the place and instrument during dev / tests. If you want to use it a bit like schema and check things at the network boundaries, then you definitely can. Just check things with s/valid?
. You can then use s/explain
and some of your own code to return helpful error messages.
@blmstrm During development you can call instrument
after all of your functions are defined to get checks throughout your system. But I'd recommend only manual checks at the edges in production.
Okay. That makes sense. Thanks for taking your time and explaining. What you are saying is exactly what I wanted to do, it just didn’t occur to me that I should create custom validation code with valid?.
Route all of your HTTP in/out through some central namespace, then perform your checks in there. Just a suggestion, it's all very new, so you might find something that works well for you after playing with it 🙂
If there are any danish clojurians in here who are looking for a job, please send me a message 🙂
@laujensen... and is working remotely an option?
@mogenslund For the right person it probably is yes
I have two maps arg
and val
and two different keys :id
in arg and fooid
in val that need to be assigned to the var id
. Either arg or val can be empty and hence I have used the below code that works but is there a syntax sugar where I can merge the two maps and then destructure them in such a way if one is nil then the other is assigned
(defn query
[arg val]
(let [{id :id, track :track} arg
{id :fooid, :or {id id}} val]
id))
lacinia-tut.run=> (query {} {:fooid 1}) # :id is nil and hence :fooid is used
1
lacinia-tut.run=> (query {:id 1} {}) # :fooid is nil and hence :id is used
1
Is there a syntactic sugar to do above in one destructuring call ?hi, i rewrite new FirebaseOptions.Builder()
to (new (.-Builder FirebaseOptions))
, but get the error Unable to resolve classname: (.-Builder FirebaseOptions)
. Tried FirebaseOptions/Builder
, as well as FirebaseOptions$Builder
suggested in #clojurescript channel. What am I doing wrong here?
Hello, I'm trying to run this example of annotation interop from "Clojure Programming". But this won't compile for me. It seems that gen-class
doesn't create the class, so I get ClassNotFoundException
.
https://github.com/clojurebook/ClojureProgramming/blob/master/ch09-annotations/src/main/clojure/com/clojurebook/annotations/junit.clj
Has something changed since the example was created?
I just made a video on how to use Clojure to interact with the StarCraft II AI API https://www.youtube.com/watch?v=hcYneRzdWV0
I’m still having trouble adding a custom pretty print writer that has all the features of pprint just for IDeref I want it to print #[object …] instead of #<Atom …>. I’m running code through pprint so checking instances on the fly and calling “print” instead of pprint isn’t an option. This may sound superfluous but it’s for a dev tool and I’ve been stuck on it for a couple days 🙂
@alex-dixon is pprint a multi-method, and you can just override the method for IDeref?
Hi. Any Specter experts here? I'm hitting a few brick walls and need some assistance.
@babelchips what's your issue?
Hi @nathanmarz - very kind of you to help! I have a couple of minor problems. Firstly I'm trying to add a new element to the end of structure but I'm just getting the data added as a value.
e.g. (s/setval [s/ALL :fields :summary s/END] [:zzzz] subResponse)
results in -----> :fields {:summary Setting up the code for blah blah [:zzzz]
When I'd like it to be ----> :fields {:summary Setting up the code for ADA & AOA on Local machine, :zzzz etc.
what's the input structure?
use backticks in slack to get it to render code clearly, e.g. (setval ALL :a data)
It's JSON parsed with Cheshire
can you paste an example?
I can't tell the type of the value for :summary
Ok here's a sample: https://pastebin.com/MgtqLCXg
I want to add another element next to :summary
ah I see, it's a string
when you transform END
on a string, you need to provide a string
by providing a vector, it just calls str
on that and appends it to the target
you can do ", :zzzz"
to get the result you want
Ah ok. And that will create a key :zzzz that I can then select later?
what do you mean? it just gets added to that string at that subvalue
I really just want to add a new element after :summary, not append to the existing value.
A new key and val insert into the structure after :summary
*inserted
so a new key/value in the "fields" map?
there's no concept of "after" for :summary as its a key in an unordered map
(setval [ALL :fields :zzzz] :some-val data)
Ok, that makes sense!
actually in this case it would be (setval [ALL (keypath "fields") :zzzz] :some-val data)
since the keys in your example are strings, not keywords
feel free to drop by the #specter channel if you have more questions
Thank you. I'll switch over now. I have one more question
I am considering writing dynamic versions of import
and require
based on https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/Reflector.java .
The idea is to be able to pass the name of the class/method in variables; something like (import-dyn (class-name :as foo))
and static methods as (foo / method-name 5 4 3)
or instance methods as (let [x (foo . 5)] (x . method-name 4 3))
where class-name and method-name are strings [require-dyn would be similar]. Has anyone already done something like this?
are you sure you need to do anything with require? require is already a function that can take a symbol
@noisesmith you are correct, the following works fine: (let [ans (symbol "clojure.core")] (require [ans :as 'foo]) (foo/+ 5 6))
the trick is the part where you call it - since if you do the require inside a function, the compiler will reject a form because the ns is not loaded at the time it is compiled, you can use resolve to work around this though, but it’s clumsy
the same issue comes up with import (or just using a dynamically loaded class and method not known at compile time in general) - you have to use clumsier constructs because the most convenient interop forms need the symbols to be known during compilation
really, the method being dynamic is harder than the class being dynamic (clojure already does implicit type reflection when it is needed for method calls)
@noisesmith I was thinking a macro. Exemplar (new-dyn ["Lexer'] "lexer" nil)
producing something like (let [class-loader (DynamicClassLoader.) lexer-class ^Lexer (.loadClass class-loader "lexer")] (Reflector/invokeConstructor lexer-class (into-array CharStream [nil]))
@phreed this is the library I was thinking of https://github.com/timmc/handy/blob/master/src/org/timmc/handy/reflect.clj
I had read the documentation for clojure.reflect
. It exposes information about the properties of a class but it is not clear how to use it to invoke methods short of invoking eval
. It was this https://groups.google.com/d/msg/clojure/YJNRnGXLr2I/jfRCjJOLVHMJ thread that lead me to clojure.lang.Reflector in the first place.
Oh, interesting
is there a nicer way to write ((fn [x y z] [x z]) ...) // I feel like there should be a nicer way o say "drop middle elem"
I guess I'm after a builtin named take101 where the 101 binary encodes which elems I want 🙂
also, it’s too bad last is O(n), while peek is O(1) but only gets the last item if the arg is a vector
=> (reduce (fn [v [n el]] (if (zero? (bit-and 5 (bit-shift-left 1 n))) v (conj v el))) [] (map-indexed vector [:a :b :c :d :e]))
[:a :c]
that uses 5 as a bit mask to build its collection
should probably use (take 64 coll) since that’s your max with a reasonable bit mask
@noisesmith: lol you win
(I guess you could use a byte-array as a bit mask for larger inputs, that makes the logic a bit messier)
(defn mt [mask lst] (keep (fn [[x y]] (if (= x 1) y)) (map vector mask lst))) (mt [1 0 1] [:a 😛 :c])
user=> (mapcat #(when-not (zero? %) [%2]) [1 0 1] [:a :b :c])
(:a :c)
in sider, is there a cmd for "eval last sexp AND INSERT result as text in current buffer" ?
yeah, mapcat is more general than typically assumed - it’s really “zero or more outputs for each input item, in order”