This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-08-14
Channels
- # beginners (116)
- # boot (6)
- # cider (16)
- # cljdoc (5)
- # cljsrn (3)
- # clojure (156)
- # clojure-conj (5)
- # clojure-finland (1)
- # clojure-italy (46)
- # clojure-mexico (36)
- # clojure-russia (2)
- # clojure-sanfrancisco (1)
- # clojure-spec (10)
- # clojure-uk (69)
- # clojurescript (71)
- # core-async (2)
- # cursive (18)
- # datomic (91)
- # duct (2)
- # editors (1)
- # emacs (5)
- # figwheel-main (11)
- # fulcro (31)
- # graphql (8)
- # hispano (1)
- # jobs (1)
- # jobs-discuss (2)
- # lambdaisland (1)
- # london-clojurians (1)
- # nyc (1)
- # off-topic (104)
- # onyx (34)
- # parinfer (3)
- # pedestal (2)
- # precept (17)
- # protorepl (2)
- # re-frame (13)
- # reagent (4)
- # ring-swagger (52)
- # shadow-cljs (92)
- # spacemacs (17)
- # sql (14)
- # tools-deps (6)
- # unrepl (4)
- # vim (39)
How can I check out all namespaces (which is not required yet) from a library dependency just like function (apropos #"regexp match")
?
I know CIDER can get those completions, so there are must a way to get those namespaces.
Don't know how it is implemented.
Is there someone using Clojure GitHub API library tentacles? How to know that my authentication is verified? (I don't know what auth for my personal access token, OAuth or OAuth2?)
I'm brainfarting over this. I have some duplicate hashmaps that i'd like to remove by id, so I'd like to produce a list of ids:
(->> '({:id 123 :val "val"}{:id 124 :val "val"} {:id 125 :val "otherval"})
(group-by :val)
(vals)
#_(map (fn [lm] (reduce (comp = #(apply dissoc % :id)) {} lm))))
;; want to return: '(124), because the removing the map that has :id 124 will make a list of unique maps.
oh and in the problem i'm facing, there are potentially other kvs in the map, and i only want to return the map if the hashmaps = each other
That might be a bit of the opposite of what you want @mfm but it would work like this
cljs.user=> (distinct-by :val '({:id 123 :val "val"}{:id 124 :val "val"} {:id 125 :val "otherval"}))
({:id 123, :val "val"} {:id 125, :val "otherval"})
thanks so far @mfikes! i'll see if i can modify distinct-by
or use a tricky argument...
Here is a transducer variant if desired https://github.com/planck-repl/planck/blob/dcf397d0af0aaf256fc6e582280de4cf2aa77e41/planck-cljs/src/planck/repl.cljs#L31
I think distinct-by
is probaby my 2nd most desired fn that is not in core. (With the 1st being a function or functions to map over maps, like mapping over the values to increment them.)
i think this is doing more of what i want:
(distinct-by (comp set #(dissoc % :id)) '({:id 123 :val "val"}{:id 124 :val "val"} {:id 125 :val "otherval"}))
=> ({:id 123, :val "val"} {:id 125, :val "otherval"})
where i now can: ignore the thing that'll always be unique (the :id), and compare against all other values in the setand to get the list of ids (the original desideratum), i do something like clojure.set/difference
If a function has this signature: [url & {:keys [a b c]}]
, then doesn't that mean it can be called with one or more arguments? Just has to be at least one.
Actually I think it would have to be an odd number, but probably that would only be worked out at runtime??
those are optional keyword args, so you can call it like this: (foo some-url :a some-value :c some-other-value)
Trouble is I'm getting an error message saying 3 args being passed is no good. In fact only one args means no error messages.
(wn/make-websocket-networking "/chsk" :push-handler (fn [m] (when @app (push-received @app m))))
according to the docs there is no url
argument: https://cljdoc.xyz/d/fulcrologic/fulcro/2.6.0-RC6/api/fulcro.websockets#make-websocket-networking
That would be the latest source. Cursive is showing me old source. And shadow-cljs using what is really being used which would be the latest I imagine. Actually I'm confused.
your project manager can show you the version you are using; lein deps :tree
for example
if all args are keyword args, any odd argument count is invalid, you'd get "no value supplied for key"
I wouldn't expect shadow-cljs to pin you to the latest version of a dep
also, if you use lein cp
you can see the actual resource being used to load the code, and look at the source - but cursive definitely automates that
cursive should be using your classpath, so I'd find it unlikely it would get the source wrong
(of course bugs will be bugs, but that would be a very weird one)
Well I can see 'url' there (first arg, before the &), so the unlikely seems to be happening no??
perhaps your deps changed since cursive started and it has a stale view of your deps?
or cursive and your process are using different classpaths...
So that fixed Cursive. The call is now underlined as red and tells me about incorrect arity, just as shadow does. Thanks all.
FYI regarding the mount vs component discussion yesterday, here's Dan Boykis' insight into why mount is better: http://danboykis.com/?p=2263
In short - it's his opinion on what is beautiful and structurally correct in Clojure
the idea that mutable globals that cannot be composed together in anyway is beautiful and structurally correct is laughable
the whole thing is basically dynamic scoping vs static scoping, which was a whole argument back in the day, and dynamic scoping can be nice for some stuff, but static scoping is the correct default
Agree with what you say about mutable globals and lack of composition. Was just pasting it here, as somebody mentioned that they couldn't understand what the attraction was (for mount)
Does deref'ing a promise tie up an OS thread, or is the calling thread parked, similar to taking from a core.async channel?
promises have nothing to do with threading machinery, your thread blocks until some other thread delivers
Yeah perhaps I didn't phrase that very well with respect to threading. But it sounds like the answer is "yes, dereferencing a promise
does block and tie up CPU resources, unlike clojure's channels
, in which the calling thread is parked (making those compute resources available for other work) until a value is delivered"?
it blocks a thread, but it doesn't busy wait or tie up CPU
Perfect, that's what I wanted to find out. Thanks! After looking at the java API again, I think my question could have been better written as "When a promise is dereferenced, is the calling thread state set to 'wait' or 'park'?" Thoughts?
That works. There is no "park" state for a thread, you need some abstraction over threads to provide that (aka a coroutine, green-thread, callback-chaining... it's called by various names)
the advantage is that you can switch a green-thread context without an actual thread context switch, which means you have more control and you don't pay the price of OS level thread machinery
Awesome, thanks again.
that said, on most operating systems threads are relatively cheap
(promises have no more to do with threading machinery than anything else that blocks a thread that is)
@jasonpepas There's a project named MAL (Make a LISP) on github (https://github.com/kanaka/mal) that's implemented a Clojure Inspired LISP interpreter in 73 different languages. One of them is Swift. There's a link in the readme to another project, MALC, that provides an LLVM compiler for MAL. Between the two, you'd have a good starting point for creating a ClojureSwift.
If I have a function that takes a map as argument, then how do I make sure I don't accidentally retrieve the wrong key when using such map?
say the function is supposed to be passed in a {:a 1}
, and I somehow think it wants a {:b 1}
, then I proceed to use :b
in the body of the function, and also when writing test for the function. I won't discover it until I deploy the service to qa environment and do a end to end integration test.
@blance I think that’s just a general question of program correctness (?) Theres nothing unique to using a map. Same issue with passing a string to a function that expects a number, for instance.
spec won't work in compile time though, and the function is not pure (upload file to s3), so I would need to write bunch of mock in order to exercise the path:thinking_face:
it’s a big topic. I’d say that there are moments where may need to program defensively by doing run-time validation. Another thing you’ll hear people say is that if you need to mock in order to test, you’re doing it wrong 🙂
I find that advice not that useful when what you are doing is primarily i/o, though, but it is a good thing to keep in mind
which I feel not really a good idea, but can't think of a valid argument.. as I guess i'm suppose to always write unit test for any code?
well the unit test should make sure that your function works as expected for all expected inputs. so the unit test just need to make sure that your function that accepts a map does the right thing. the unit test can’t possibly test whether other functions call that function properly
another approach here is to spec the function and exercise the function and the caller, if they use the spec, the only thing left is to make sure the spec is correct
I could gave typo in spec as well :( and I would need to exercise all path calling that function which would require lots of mocking I guess
"exercise" has a specific meaning with spec- inputs are generated that match the spec, and your code is executed with each one
the idea is that instead of having to verify that all your functions are doing the right thing, you make them use the same spec, you verify the specs carefully, and the spec is used to ensure each one behaves as expected (this means you don't have to write your own tests for conformance - the inputs are generated for you)
this isn't the only way to do things, but it's how we do things at my day job and it does work
i really like the idea of generative testing, but most of our code are doing side effects 😞
yeah, to be really effective, it requires code that isolates side effects from data transformations (which is often a good thing btw, and clojure offers multiple tools to facilitate that pattern)
but if you just have a bunch of state updating functions, by definition you can only use integration tests, generative tests and unit tests aren't helpful
thanks for the suggestion, that makes a lot of sense. I'll try to convince my teammate:)
Guys i'm having some warnings on eastwood lint on that fn
(defn count-merchant-transactions
"Count Merchant Last Transactions for a Merchant"
[^Transaction transaction, lastTransactions]
(let
[
merchants (filter (fn [x] use transaction (= (:merchant x) (:merchant transaction))) lastTransactions)
]
(count merchants)
))
Eastwood warnings:
core.clj:40:32: unused-ret-vals: Var value is discarded: use
core.clj:40:36: unused-ret-vals: Local value is discarded: transaction
Am I doing it wrong? how can I improve this fn
or the entirely function?you have use
and transaction
, just sitting there, they aren't part of the return value of the function and they aren't used in an expression that might have side effects
it isn't clear what the use transaction
is intended to accomplish, but as is it definitely isn't doing anything, which is why eastwood complained about it
i was thinking on pass transaction value throw (fn) , but it already are in the context
@UC7MQBH6H yeah, you never need to use
names from outer scopes in Clojure, like you do in PHP. you just reference them