This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-11-23
Channels
- # aws (2)
- # beginners (57)
- # boot (63)
- # cider (7)
- # clara (1)
- # cljs-dev (1)
- # cljsrn (5)
- # clojure (68)
- # clojure-brasil (1)
- # clojure-dusseldorf (2)
- # clojure-greece (10)
- # clojure-italy (29)
- # clojure-russia (1)
- # clojure-spec (9)
- # clojure-uk (66)
- # clojurescript (16)
- # cursive (18)
- # datomic (19)
- # docker (3)
- # figwheel (2)
- # fulcro (61)
- # instaparse (7)
- # jobs (1)
- # luminus (5)
- # lumo (47)
- # mount (6)
- # off-topic (13)
- # onyx (39)
- # planck (4)
- # portkey (2)
- # re-frame (28)
- # ring (6)
- # ring-swagger (30)
- # rum (3)
- # shadow-cljs (142)
- # spacemacs (5)
- # sql (2)
- # unrepl (61)
- # untangled (2)
this is my simple user.clj
(ns ring-it.user
(:require [reloaded.repl :refer [system reset stop]]
[ring-it.core]))
(reloaded.repl/set-init! #'ring-it.core/create-system)
@bravilogy I’m guessing the channel is going to be less active right now because the US has a big holiday which for many people starts with traveling tonight or early tomorrow morning
I bet you’ll get replies if you ask this weekend or Monday
reloaded workflow coined by stuartsierra, a clojure workflow as demonstrated with Component https://cb.codes/a-tutorial-of-stuart-sierras-component-for-clojure/ weavejester adopted the workflow with https://github.com/weavejester/reloaded.repl, https://github.com/weavejester/integrant
@lovuikeng, I went through all of those 🙂 perhaps there’s an issue with the version.. thanks anyway
@qqq I can't think of a way that doesn't involve duplication... can you give a bit more context?
For example, you can do {:keys [a b c] :as data}
but data
will be the whole of what you bind, not just those keys...
(or maybe (every? some? [a b c])
for whatever keys you destructure?)
sorry, I meant to say: (let [{:keys [a b c]} ... ] (assert a) (assert b) (assert c)) ^-- is there a shorthand for this
@qqq Well, I'd say (assert (every? some? [a b c]))
is going to be clearer as the number of keys increases.
@igrishaev That's not what he's asking tho' -- he doesn't want defaults, he wants failure-on-nil.
I don't want default values -- if a field is nil, it should assert and die, as something went wrong
@seancorfield: I think your solution is opt, if I try to write amacro, it becomes very messy as I have to basically parse destructuring
You could probably write a macro that expands to (let {{:keys ~keys} ~value] (assert (every? some? ~keys)) ...)
That would remove the repetition...
yeah, but this wouldn't play well with multi part let-destructs, like
(let [{:keys [...]} objA
{:keys [...]} objB]
...)
You'd have to have it nested... which I think logically it would need to be, given the fail-on-nil requirement?
it's okay to destructure objB even if some part of objA is nil, they're not 'nested', they're two separate objects
Well, then write the macro to do that 🙂
But still, take a look at clojure.spec. It has useful instrument
function that wraps another function with data checks. And having schemes declared explicitly makes your code more clear. Instead, checking data every time in place leads to spagetty code.
@qqq You could indeed write such a macro... @igrishaev instrument
has an overhead that you might not want to pay in production. It is better to be explicit with s/valid?
or s/assert
.
And relying on instrument
when you actually want the nil
-checks performed explicitly in production is definitely not something I'd recommend (as a heavy user of spec myself).
I'd actually want something even morespecy- .... only allows keys taht are part of s/keys of the spec
@seancorfield yes, agree with your points.
If you have a spec with s/keys
, you can call s/form
on it and destructure to get the list of :req
or :req-un
keys. Then you can programmatically use that key list to validate the data.
(if the spec is more complex -- say s/and
over s/keys
-- then you'll need to do some work there... and maybe you'll need to parse s/merge
etc so it depends how "smart" you might want to be?)
You could of course write a spec for those keys where each value was specified as non-`nil`able... but you'd still have to call s/valid?
or something...
boot.user=> (s/def ::foo (s/keys :req-un [::a ::b ::c]))
:boot.user/foo
boot.user=> (s/form ::foo)
(clojure.spec.alpha/keys :req-un [:boot.user/a :boot.user/b :boot.user/c])
boot.user=> (let [[_ _ keys] (s/form ::foo)] (println (map name keys)))
(a b c)
nil
1. @seancorfield: this is very cool, s/form
is awesome and I will be using it in the future
2. asserting that the value associated with the key is non-nil does NOT solve my problem
my problem is that I sometimes specify the wrong key -- i.e. the key doesn't even exist in the map -- that's the problem I'm trying to solve
I use s/form a lot, both in my spec serialize library, and to be able to edit a map based on the spec, it’s great.
@qqq metosin/spec-tools has a s/form parser, it extracts the keys from s/keys (also s/merge ones), and utilities for dropping out undefined keys.
@bronsa is 1412 like take
? I somehow expected it to be like doing (take (* n (count s)) (cycle s))
so that would change its degree of laziness
but of course if you count on a precise amount of laziness, you are probably doing something wrong
because you count the collection argument
so I would assume it would realize the full input if it was lazy, right away, where the original would be lazier
hmm, never mind, looks like cycle already forces the arg
oh, a chunk, of course
+user=> (def c (cycle (map print (range 1000))))
012345678910111213141516171819202122232425262728293031#'user/c
so that would change from realizing 32 items to realizing 1000
hi everyone. if anyone uses spacemacs, could you tell me how to switch between open panes please? 😄 there’s literally no tutorial I could find that says this
Pretty sure you do space 1
for the first pane, space 2
for the second and so on - unless I misunderstand the question.
@noisesmith the impl in that ticket doesn't actually count anyway
Hello people! We making a study group about Clojure in Brazil. This table of contents is good to beginners learn the language? https://github.com/training-center/clojure-study-group/blob/master/material/roadmap.md
@w.oliveira542 maybe interacting with the JVM could be earlier? (or at least an intro to the useful stuff about figuring out how java stuff works - what to look for in javadoc for example?)
Maybe into second session, @noisesmith?
Sure - it's hard for me to say without seeing a more detailed curriculum of course, just a thought. I think people could save a lot of trouble if they were more pragmatic about using host interop