This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-02-27
Channels
- # bangalore-clj (1)
- # beginners (11)
- # boot (23)
- # business (2)
- # cider (43)
- # cljs-dev (65)
- # cljsjs (17)
- # cljsrn (4)
- # clojure (144)
- # clojure-austin (4)
- # clojure-berlin (3)
- # clojure-finland (4)
- # clojure-nl (2)
- # clojure-russia (13)
- # clojure-spec (73)
- # clojure-uk (42)
- # clojured (2)
- # clojurescript (166)
- # core-matrix (4)
- # cursive (24)
- # datomic (39)
- # dirac (8)
- # hoplon (97)
- # jobs (2)
- # jobs-rus (11)
- # juxt (16)
- # lein-figwheel (8)
- # leiningen (1)
- # luminus (5)
- # lumo (46)
- # off-topic (1)
- # om (39)
- # onyx (43)
- # overtone (1)
- # pedestal (3)
- # perun (6)
- # play-clj (3)
- # protorepl (14)
- # re-frame (21)
- # reagent (25)
- # remote-jobs (1)
- # ring (1)
- # robots (4)
- # rum (13)
- # specter (5)
- # untangled (72)
- # yada (62)
I have a problem with Java Interfaces and reify, did anyone of you ever reify a method from a Java Interface with return type void?
For Java/Clojure Interop I need the method to run some side effects, but I am always getting a error
My call looks like this right now. I added void after someone suggested it at http://stackoverflow.com
( http://stackoverflow.com/questions/42473644/how-to-reify-java-interfaces-with-overloaded-method )
Works like a charm 🙂 Thank you very much!
That’s a neat feature for next time, thank you
Does someone has a reference how to start / spawn a process, send him strings, read strings from him (and finally send him a quit?) in Clojure?!
So the clojure qeuivalent to this http://stackoverflow.com/questions/706989/how-to-call-an-external-program-in-python-and-retrieve-the-output-and-return-cod
You probably want the Java Process API. Clojure probably just leverages JVM instead of having its own lib for this.
clojure has sh. And I found this: https://github.com/Raynes/conch
unless there's some particular feature you need from the clj lib (which is not clear in which case), it may be easier to just go with java docs, as they're bery well written and very well tested
one lesson I learned a hard way is: unles the clj library is really really really popular (as in half the clj community uses it), the following will probably be true: 1) more sample code on interenet for java api 2) more stack overflow responses for java api 3) and in general, easier to just deal with the java api since clj interop is so nicely done
The other lesson I have learned in the same area is: If you're writing a shell script, write a shell script. Don't write shell scripts in any other languages. It's OK to shell out to a simple command but as soon as you find yourself building a pipeline you should extract that into a shell script and shell out to that instead.
IOW if you see things like |
, &&
, ||
or ;
then you need to extract it out of Clojure or else you'll have a horrible time debugging it.
I've seen that mistake made in PHP, Python, Ruby and – most recently – Clojure. It has never ended well. 🙂
though I have to admit, I can't think of the last time I've had to write a shell script -- between elisp and boot, I rarely have to chain multiple shell cmds together
I guess if I had to glue multiple external programs together, shell scripts wuld be the only way to go
True. Might be better to write a bash script and then mangle the output in clojure for processing...
all opening books so far are taken from grandmaster games. As far as I know nowone has created yet an opening book with the strong engines like stockfish, komodo, etc.
edlich: does an "opening book" from strong engines just mean a precomputation of the engine's evaluation for an opening position? to speed up actual gameplay?
and nobody's done this before because they didn't trust strong engines to evaluate opening positions until recently?
But I refuse to take a book generated from strong players with ELO 2400-2800 if the current engines have ELO 3300.
But I should ask this on Talkchess http://www.talkchess.com/forum/viewforum.php?f=7
okay; so it's possible that these 3300 engines are still really bad at openings
(especially if their designers haven't been focused on openings)
but even if that's true you might be able to get quality results by doing sufficiently deep searches
(I don't actually know anything about this, just speculating)
Hence I want to fork this engines with a fen position and get the calculation back for eval.
I dream of calling: stockfish8_64_bmi2.exe FEN and the script does this for all best 3 moves and 3-5 moves deep.
I have a dev-settings.edn
. Can I use functions in that file? For example, maybe I'd like to use a flag to connect to a different database. :database (database :dev)
After a quick try I just get lojure.lang.Symbol cannot be cast to java.util.Map$Entry
🙂
there's an undocumented reader macro
(read-string "#=(println :boom)")
:boom
nil
that's not edn though
@kauko, you could abuse that to do calculations when reading an EDN file
so if it works then the filename dev-settings.edn
is misleading, at least
@gfredericks yeah but you could use read-string to read the file
that's true 😉
dev-settings.edn++
yeah I don't recommend it
there's literally dozens of configuration libraries out there like https://github.com/weavejester/environ
ah wow aero looks great
you gotta watch out for those 4 letter libraries
😆 (aero is edn really, ok?)
Hi everyone, ah I love clojurians. Always get the help i need... and sometimes i can offer some 🙂
I'm trying to incorporate new information into an existing app state atom
(def nf-atom (atom { :entries [ {
:id 5
:title "a-title-goes-here"
:score 10}
{:id 6
:title "newer-item"
:score 30}]}))
Say I have a map that says {:id 6, :score 85}
as fresh data. How can I incorporate this new information into my existing atom? I think assoc-in would be the right choice, but I'm not certain how to "match on :id" and affect only the one...
@moxaj no such reason, other than I don't know how xD ...are you saying there's a way to index atom submaps on a :key?
sova: i'd suggest (atom {6 {:id 6 :title "newer-item}})
instead of the :entries
array, unless there is a reason not to.
@moxaj @jrychter Ah I see. yes, my app state atom has gotta stay the way it is, i'm using it with om.next ... i'll have to figure out a way that plays nicely with the existing structure since there's already a lot depending on how the data is stored
@jrychter although merge works almost perfectly... I just want to overwrite the :id matching map with newer data... hrm
doing it my naive way it adds a new map to the vector, which is closer than i was.
I don't have very many things on the clientside though, so I think that I could just walk through (the vec of maps) and find the matching one, and update some attribs?
if only there were a smash in addition to merge xD
If it helps @sova you can assoc
on a vector, using the index as a key: (assoc [:a :b :c :d] 2 :x)
=> [:a :b :x :d]
You’d need to know the index of each :id
— and you’d have to be careful not to have code push items onto the front of that vector (since the index of an element could change).
@seancorfield Cool, that is potentially helpful. Although I'm still going to look for a way to do it that doesn't require me messing with indices...
and you are not ok with (swap! nf-atom update :entries #(for [item %] (if (= (:id item) id-to-update) new-item item))) ?
@sova With Specter you can do it like this:
(defn entry-nav [id]
(path :entries
ALL
(selected? :id #(= % id))))
(swap! inf-atom
(fn [m]
(transform (entry-nav (:id new-data))
#(merge % new-data) m)))
this replaces:
(defn swap-fn
[{v :entries :as nf} d]
(loop [i 0]
(when-let [m (get v i)]
(if (= (:id m) (:id d))
(assoc-in nf [:entries i] d)
(recur (inc i))))))
(swap! nf-atom swap-fn {:id 6 :title "hey-o" :score 90})
Then you can re-use entry-nav
for other transformations or for querying, such as:
(select-any (entry-nav 5) @inf-atom)
;; => {:id 5, :title "a-title-goes-here", :score 10}
@joshjones "do you want to replace the data that matches the id, or merge it in?" ... < I want to merge it in (keep original data & overwrite matching keys)
Specter looks amazing... thanks for pointing to that.
(swap! nf-atom swap-fn {:id 6 :title "hey-o" :new-key 42})
=>
{:entries [{:id 5, :title "a-title-goes-here", :score 10}
{:id 6, :title "hey-o", :score 30, :new-key 42}]}
@sovaUnrelated to clojure question: It seems that people are starting to turn to me, more and more for teh answers to their problems. In many cases the answer is a well worded search engine search away. How do I encourage people to stop asking me these questions, politely?
it does. encourage code reviews as an async way to improve code instead of blocking your peers to wait for an answer
(defn swap-fn
[{v :entries :as nf} d]
(loop [i 0]
(if-let [m (get v i)]
(if (= (:id m) (:id d))
(update-in nf [:entries i] merge d)
(recur (inc i)))
nf)))
another user posted a solution using for
earlier which did not work, but this working version is cleaner than the above imo:
(defn swap-fn
[{v :entries :as nf} d]
(assoc nf :entries
(vec (for [entry v]
(if (= (:id entry) (:id d))
(merge entry d)
entry)))))
@joshjones thanks!!!
that werks perfectly
it’s not pretty really, but neither is the structure you are having (or choosing?) to use 😉
yes, I admit it's not the best it could be, but I've already built most of the pirate ship around it.
I wish there were an interactive primer on @atoms
where I could learn really well all the data manipulation funkshns
Either way, as long as it works, which it does 😃
@nathanmarz: curious, would this be a sub par solution to yours?
(defn f [xs {:keys [id] :as data}]
(transform [:entries ALL #(= (:id %) id)]
#(merge % data)
xs))
=> (swap! nf-atom f {:id 6, :score 85})
{:entries [{:id 5, :title "a-title-goes-here", :score 10} {:id 6, :title "newer-item", :score 85}]}
@tolitius no, it's similar
I like doing things like entry-nav
so that I can think about my transformations in terms of application concepts instead of lower-level data structure concepts
@nathanmarz: makes sense, you also have an :id
concept baked into the entry-nav
, would that be an example of an "application concept" in this context?
i guess so
Is there way to make copy of this structure, but filled with zeroes instead of original values?
[[[0.45 0.78]
[-0.12 0.13]]
[[1.5] [-2.3]]]
@kgofhedgehogs (with specter):
=> xs
[[[0.45 0.78] [-0.12 0.13]] [[1.5] [-2.3]]]
=> (setval [(walker number?)] 0 xs)
[[[0 0] [0 0]] [[0] [0]]]
I need to figure out Mr. Anderson in boot so I can use things like Specter in libraries.
let kw be a keyword; is there ever a situation where (get obj kw) and (kw obj) return different values?
I don't think so, given the preconditions you stated. the behaviour if kw is nil is different though
(:foo {} :bar) => :bar
oh I didn't know kw's took not-found values. so maybe the code was originally written but someone uninformed like me 😆
AFAIK the keyword function syntax isn’t any different to get
🙂
Also: ({} :foo :bar) => :bar
@weavejester: your handle looked familiar, so I looked you up on github, and saw you listed as "freelance clojure dev" -- could you DM me your conditions for freelance work? [hourly wage, min project size, etc ... ]