This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-06-12
Channels
- # beginners (81)
- # boot (29)
- # cider (7)
- # cljs-dev (147)
- # cljsrn (5)
- # clojure (121)
- # clojure-austin (4)
- # clojure-conj (4)
- # clojure-italy (9)
- # clojure-russia (20)
- # clojure-sg (1)
- # clojure-spec (25)
- # clojure-uk (34)
- # clojurescript (137)
- # cryogen (2)
- # cursive (1)
- # data-science (1)
- # datomic (29)
- # events (9)
- # figwheel (1)
- # hoplon (14)
- # jobs (2)
- # luminus (2)
- # off-topic (7)
- # om (36)
- # onyx (6)
- # parinfer (14)
- # re-frame (13)
- # reagent (74)
- # specter (2)
- # test-check (1)
- # untangled (43)
- # vim (14)
- # yada (36)
I've been reading about stateful transducers and I'm having trouble understanding a thing: Why should the state be visible to other threads (as volatile
s are) at all?
@j-po, If you hang a transducer on an async channel, the transducer is not pinned to any particular thread, although access should be coordinated by the async system. Right?
give it a name
(fn foo [] ... (... foo ...))
@noisesmith : += 0.5
Somybody tried https://github.com/sveri/closp with 3.0.0? Can't run lein migrate
as it doesn't exist.
@danielgrosse I removed the migrate dependency and did the migration by hand
None of the existing migration libs fitted my needs and in a production environment I dont want to have it automatized anyway
the docs are not rewritten yet, btw. as I am currently working on something different which I will show today at our meetup 😉
Okay. Additionally I get an error, that the user ns you'll define in {:repl-option {:init-ns {closp.user}} isn't available
4clojure question, #143. I came up with the following solution which fails the first unit test on the site but passes locally for me. Any ideas on what Im doing wrong?
also notably annoying that the question doesn't explicitly say I should produce a lazy sequence; I had a reduce
based solution that just fails on the last test...
what is the it asking you to do @kevinludwig ?
it says "You failed the unit tests"
which typically means the output didn't match what it expected
but I verified in the REPL that the output is identical
oh sorry.
"Insert between two items"
"Write a function that takes a two-argument predicate, a value, and a collection; and returns a new collection where the value is inserted between every two items that satisfy the predicate."
Unit test they give is (= '(1 :less 6 :less 7 4 3) (__ < :less [1 6 7 4 3]))
got an answer, https://stackoverflow.com/questions/44501574/insert-between-two-items-on-4clojure-com
I’m having some trouble figuring out how to configure eastwood to ignore an isolated warning
the macroexpansion of compojure-api’s POST produces a (merge map) expression, and eastwood gets upset because it’s just one map
(compojure-api has a change to fix this in master, but it’s not in release yet)
I have an eastwood-config.clj
file that looks like
(disable-warning
{:linter :suspicious-expression
:within-depth nil
:if-inside-macroexpansion-of '#{compojure.api.core/POST
compojure.api.core/GET
compojure.api.sweet/POST
compojure.api.sweet/GET}})
and in my project.clj I have :eastwood {:config-files ["eastwood-config.clj"]}
but the warnings still show up
I want to do something like below to destructure arrays in a let context. Is there something better than this in clojure.core already that I overlooked?
(defn intersplit [coll]
(when (coll? (first coll))
(partition (count coll) (apply interleave coll))))
user> (intersplit [[1 2 3] [4 5 6] [7 8 9]])
((1 4 7) (2 5 8) (3 6 9))
@waffletower (apply map list coll)
nice par! thanks!
much more general approach
bonus, you can define it as (partial apply map list)
and people will squint at it and have no idea what it’s for
(not actually a bonus)
I already added a doc string 🙂
but your reminder that I can use map
as an argument to apply
feels like I held an epic spell staff for a moment 🤓
@michaelblume unrelated to how to configure eastwood, but the compojure-api 2.0.0-alpha2 should be out in a day or two (with initial spec coercion, finally!)
@ikitommi thanks =)
is there any convenient function for validating that data is of the form of a specific record?
as in
(defrecord Circle [radius])
(def circle (->Circle {:radius 1}))
(is-circle circle) ; => true
is there any function like is-circle
?
or maybe even an is-record-type Circle
#(instance? Circle %)
ah, excellent. Thanks!
Now will that apply if I have a map that is isomorphic to the record? If not, can I convert that map to an instance of the record?
(Circle->map {:radius 1})
which is actually what you should be using in your code example above
that example is wrong
(def circle (->Circle 1))
is what you would use
those two are equivalent here
ah, I see. Thanks! That should be map->Circle
, right? I couldn't find Circle->map
yes, sorry
darn, it seems that map->Circle happily returns true in this situation (instance? Circle (map->Circle {:l 2}))
so this is a valid Circle #user.Circle{:radius nil, :l 2}
which means that I can't use this for validation of request JSON from Compojure
that is a valid Circle - records are open by design
it’s not really public API, but you can also utilize Circle/getBasis
user=> (Circle/getBasis)
[radius]
to tell you the expected fields
that's cool, I'll keep that in mind. There's no way to detect that a map contains all the default fields -- non-`nil` -- of a record, without making a custom function, I guess?
no, but getBasis is enough to build that
yeah, I can see that mapping that over an instance would be enough. I'll get on it 🙂
considering you mention it’s not considered part of the official api, is Circle/getBasis
less hacky than (keys (map->Circle {}))
?
either seems fine (although I’d defonce the latter)
I think getBasis always returns them in the definition order (or at least that would be my expectation)
oh sorry, read that as former
agreed - the latter would not be good for determining field order for positional constructor
^ but then if you have the list of field names you don't need the positional constructor 🙂
Is it possible to ^
Or do I have to use (compile …)
if you are aot compiling 1. don't use a single segment namespace 2. use a build tool
and are just making your life more painful now, by trying to figure this out, and someone else's life more painful in the future when your code base hits the edge cases around aot compilation
kinda, you can pick one and there’s usually some adapter classes to bridge everything into it
"Logging macros which delegate to a specific logging implementation. At runtime a specific implementation is selected from, in order, slf4j, Apache commons-logging, log4j2, log4j, and finally java.util.logging."
@hiredman thanks, I understand this is a completely contrived example. I want to demonstrate compiling a clj to a class and running it from the command line without using lein or repl or any other means.
But thanks for the response!
Go on.
Not sure I follow your analogy.
I don't know to what audience you are using that demo, but my guess would be clojure novices
Sure, which is why there are other examples further in the demonstration.
But thanks.
@stuartrexking in my experience AOT compilation is only useful for a few java interop edge cases these days
@stuartrexking might be more interesting to show an example of loading your clojure main from the Java CLI ala
java -cp ... clojure.main -m my.clojure.namespace
Yeah, I have that one.
I would never ever tell a novice aot exists, if you tell them it exists they think they need to use it
I just discovered pre- and post-conditions. While it seems to be working in the REPL, it doesn't seem to be working in the tests. Are pre-conditions disabled during testing?