This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-05-30
Channels
- # arachne (2)
- # beginners (8)
- # boot (19)
- # chestnut (2)
- # cider (1)
- # clara (1)
- # cljs-dev (31)
- # cljsrn (82)
- # clojure (163)
- # clojure-dusseldorf (7)
- # clojure-greece (1)
- # clojure-italy (4)
- # clojure-norway (3)
- # clojure-russia (24)
- # clojure-sg (5)
- # clojure-spec (6)
- # clojure-uk (42)
- # clojurescript (239)
- # core-async (4)
- # cursive (10)
- # data-science (18)
- # datascript (1)
- # datomic (110)
- # emacs (16)
- # euroclojure (1)
- # events (1)
- # figwheel (1)
- # hoplon (22)
- # keechma (2)
- # klipse (5)
- # lein-figwheel (3)
- # leiningen (7)
- # luminus (27)
- # melbourne (2)
- # mount (5)
- # nyc (7)
- # off-topic (35)
- # om (20)
- # onyx (49)
- # pedestal (41)
- # re-frame (31)
- # reagent (18)
- # remote-jobs (9)
- # ring (4)
- # ring-swagger (1)
- # spacemacs (6)
- # specter (6)
- # uncomplicate (3)
- # unrepl (9)
- # untangled (54)
- # yada (11)
I'm hiring in Melbourne right now. If you want to talk please come to either the melbourne-distributed or clj-melb meetups
I'm afraid I'm not considering remote this year, though almost all my clients over the last five years have been remote
I’m tired. What is the simple way to split a string, ignoring space, comma, or newlines?
@bherrmann One small bit of golf: (remove empty? ...)
Thanks @dpsutton yea, and tabs are good to pull out. @mfikes thanks, remove and empty good idea
@bherrmann (re-seq #"[^ ,\n]+" "table \n, , , flock")
Invert the regex, use re-seq
.
do people use edn as a configuration format? How’s that working out? It seems like clojure-the-language really wants me to use namespaced keywords, but that seems very verbose when using EDN since it doesn’t seem to have ns aliases.
edn has the namespace aliases of the namespace reading it, I use edn for some config, without any namespaced keywords
I stand corrected - namespace aliases don't actually work when using clojure.edn
namespace aliases do work with regular read / read-string though
@noisesmith read-string will evaluate code though.
dominicm: the #= reader macro does not exist on cljs
it only remains on clj because they don’t break compatibility
it’s considered a misfeature as far as I know
yes, that’s a good point
If some way to evaluate during read-string was discovered in cljs, I doubt anyone would rush to fix it. As that's not it's purpose, right?
@lvh I find it works pretty well using un-namespaced EDN, see https://github.com/juxt/edge/blob/master/resources/config.edn and https://github.com/juxt/edge/blob/master/src/edge/system.clj
You can also use the new namespace aliased maps in EDN (at least with clojure.edn):
(edn/read-string "{:test-key #:test{:key \"a\" :foo :bar :tie/fighter :pewpew}}")
=> {:test-key {:test/key "a", :test/foo :bar, :tie/fighter :pewpew}}
thats:
{:test-key #:test{:key "a"
:foo :bar
:tie/fighter :pewpew}}
First public look at Sabres editor, 100% clojure/clojurescript-driven CMS/eCommerce platform. Feedback is welcomed: https://news.ycombinator.com/item?id=14443969
@laujensen Just FYI: Upvoting this with the direct link will probably trigger voting ring detection and pull it real quick. Better to go to /new
and upvote there.
rauh, thanks for the tip, I wasnt aware it wold trigger voting, I just wanted to focus the discussion to that page
Hello everyone, I have an atom which stores hash-map. Is there a way to create a reference which points at an specific key inside an atom-hash-map, that whenever I change that reference, the hash-map-atom is also changed?
@burke Something like cursor
in Reagent?
A) Use a function that derefs and dispatches the map. +laziness; -read-only, unless you implement another arity for swapping with update; -the API (function call) is different from atoms (deref)
B) Create a watch to listen for changes in the source atom and update the destination atom with the part of the source you're interested in. +same API as atoms; -read-only, unless you implement a watch the other direction, but then you have to deal with a recursive dependency; -eager
C) implement your own 'computed' data type. This is tricky, but should be doable by implementing deref in deftype. -serious business, race conditions if you're not careful
I'm honestly wondering why I'm not able to find implementations of C on the internet. Someone must have wanted to something like that in the past. Maybe there are some serious issues with computed values, depending on atoms?
I'd go with A.
I found this but as I said, this stuff is tricky https://gist.github.com/aeriksson/2ca17d3586e6131a484c
also https://github.com/aaronc/freactive.core, this looks better. But still alpha.
@not-raspberry thanks for your answer. 👍 Luckily I have this problem while working on a reagent app, so maybe using cursor is the best way to go. I thought that something like cursor/pointer is part of clojure.
Then you're in luck. It's as easy (not really simple) as (:require [reagent.core :as r])
in ns
and then e.g. (def date-to (r/cursor filtering [:date-to]))
in the code.
not-raspberry: Why do I need to :refer [reaction]
instead of :refer [cursor]
, and then use ... (cursor filtering [:date-to])
?
because I copied the wrong code. And the second thing is just an example.
you only need (:require [reagent.core :as r])
🙂
reactions are nice too, btw.
I'll fix the example in the parent message.
I have a fn with :pre
assertions, and I'm struggling to with-redefs
it...
is it possible?
IE (defn some-fn [input] {:pre [(valid-schema? input)]} ...)
(with-redefs [valid-schema? (constantly true)] ...)
the most likely reason to have issues with with-redefs are not forcing lazy values inside the scope of the with-redefs, or doing with-redefs from multiple threads
a new reason for with-redefs to not work is the direct linking stuff, but you have to opt in to turning that on
what is the idiomatic way to build something that: (1) is similar to atom, EXCEPT (2) (swap! atm f) <-- f can have side effects (3) instead of doing things optimistically, it's basically:: lock atom run f unlock atom Is there a primitive like this? If not, how can I build it?
Isn't that pretty much exactly what the STM is for??
I'm writing a wrapper about JCuda and it has functions like: (JCuda/Pointer.) (JCuda/cudaMemalloc pointer size) (JCuda/cudaFree pointer) (JCuda/cudaMemCpy pointer host) (JCuda/cudaMemCpyToHost pointer host) ...
and I need a nice way to wrap this "Pointer" object so that [1] I can only have access to latestcopy, and not historical values
of the clojure mutable containers, agent is the one that will actually serialize access in a way that is safe for wrapping an immutable value, but they are a little tricky to use properly
but are you sure you need a mutable container? couldn’t a deftype that has access to JCuda api also own access to the API ?
do you need to control access to the state, apart from the access control provided by the lib?
or is the wrapper a question of having a nicer api to what it offers already?
but atoms should never be used to wrap something stateful
and the stateful thing already provides the functionality to access its latest value
I don’t see what an atom even adds there that has value
@mobileink: I don't know what diff between "state variable" and "state" is.
right, then use the original thing provided by JCuda, or wrap it in deftype if you need something more friendly
but also consider whether deftype actually adds anything - what would deftype do that just using the object JCuda offers directly wouldn’t?
right. do you need syntactic simplification or abstraction? if not, stick with interop.
https://www.reddit.com/r/Clojure/comments/30d4mr/possibility_of_creating_a_clojure_version_of_clos/
why do you need to mutate anything?
@qqq I would just define a single random object to use as your lock, and then use locking
https://clojuredocs.org/clojure.core/locking
the object you wrap already mutates
having your own mutation on top just adds complexity
you could even use locking
on an atom that you update inside the locking
body if you want to also update some state
these are very good questions, and the fact I can't anwer them off the top of my head means I haven't expl9ored the possible impl space
@bfabry no I am sorry that is just pathological
that’s not what atoms are for, and it is just asking for deadlocks or race conditions
unless a thread up and dies altogether, which is going to cause deadlocks in most transactional things
if you're in a situation where threads can get killed mid-work and the system continues then yeah you need to think harder
OK, to back up a moment, we haven’t established that atoms have any feature that qqq actually needs here. He’s already interacting with a stateful object.
that would be odd though, and probably only occurring in a case where you're already using some higher-level thread coordination abstraction. in which case you should use that
@lxsameer that depends on what you mean by "like". composition is "like" inheritance, to me.
hmmmm, Let's say I have three protocol with almost the same interface, how can I check whether a record satisfies one them ?
mobileink: you can implement a protocol, that’s as close and as far as you’ll get
a protocol can’t extend another protocol
i stand corrected. you can compose protocol implementation using extend stuff, though, which is almost as good.
right, I’m certain that the right answer is just to have separate protocols and extend each of them as apropriate (whether he’s ready to accept it or not)
yeah. haven't ever really thought about extending prorocols. i guess if it filled a real need RH would have thought of it. ;)
if it was a feature, it would be easier to have eg. an extensible hashmap type
but hey, defrecord is a nice replacement for that
i've crossed the tipping point, where i stop saying "they didn't think of x" and just accept that in fact RH undoubtedly did think of it, better than i did, heh.
heh, that’s a good rule of thumb for sure
extend-protocol
sounds like it extends a protocol, but it actually extends multiple types with a single protocol
That's a strange use-case. Usually you see one protocol with multiple related/shared implementations, like this: https://github.com/clojure/clojure/blob/d7e92e5d71ca2cf4503165e551859207ba709ddf/src/clj/clojure/java/io.clj#L209-L224
actually above I said object/type should've been type/class. You can't extend objects in clojure. I was thinking of ruby
the thing is I'm trying to have different components. normal components follows the Lifecycle protocol. But database components should follow DatabaseLifecycle protocol which have two more functions than Lifecycle
that’s when you implement two protocols
@noisesmith so how is the right way to do it ?
(defrecord Foo [] Lifecycle (start [this] …) (stop [this] …) Database (connection [this] …))
where start and stop likely invoke methods from Database inside their implementation
which is why we have a this arg, totally normal
@noisesmith ow i get it now
I have stupid problem, I have 2 files with JSON-files and every line is a JSON-object. I’d like to automatically generate on runtime test-cases for all of the line-pairs to check if they are the same
I made this kind of macro, and it works wonderfully in repl - but when running it as a tests it doesn’t work anymore because eval is not allowed inside macro
(defmacro expands [f lst-a lst-b]
(let [ar (map (fn [[a b]]
`(~f ~a ~b))
(map vector (eval lst-a) (eval lst-b)))]
`(do [email protected])))
(expands expect (load-list-1) (load-list-2))
why does this need eval?
well, actually it’s wrong but otherwise load-list-1 and load-list-2 will be forms, not evaluated forms (as in lists)
if they are inside parens in the form you emit, they will be called
well the map in the second line is generating the code if load-list-x is just evaluated as lists
right, but you could emit the whole let
there’s no reason not to
(I mean yeah it would require some refactoring, but it would get rid of a needless eval)
clojure.test/is can be used in a function
it’s very flexible
@theikkila Isn't checking if all line pairs are the same, the same as checking if the lists are same (is (= (load-list-1) (load-list-2))
?
And even if you want to check each item separately why would this need a macro? (doall (map (fn [a b] (is (= a b))) (load-list-1) (load-list-2))
Clojure.test cases don't have to be generated by macro, you can just run these in doseq or map, and I presume expectations will work similarly
so if one case fails I don’t want to clutter with working stuff, the printing is not very pretty with huge vectors of stuff
I’d replace (doall (map …)) with (run! …) except run! only takes one collection arg, anyway dorun is a better fit
Did you try with expectations?