This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-06-05
Channels
- # announcements (10)
- # beginners (59)
- # calva (172)
- # cider (13)
- # clj-kondo (1)
- # cljdoc (10)
- # cljs-dev (4)
- # cljsrn (65)
- # clojure (144)
- # clojure-europe (2)
- # clojure-italy (26)
- # clojure-losangeles (1)
- # clojure-nl (14)
- # clojure-spec (26)
- # clojure-uk (91)
- # clojurescript (75)
- # core-async (53)
- # cursive (11)
- # datomic (16)
- # fulcro (42)
- # graalvm (29)
- # graphql (9)
- # kaocha (3)
- # leiningen (22)
- # off-topic (26)
- # qa (1)
- # re-frame (3)
- # reagent (7)
- # reitit (10)
- # rewrite-clj (56)
- # robots (1)
- # shadow-cljs (107)
- # spacemacs (10)
- # specter (5)
- # sql (15)
- # tools-deps (39)
- # vim (11)
@hlolli Remember that macros take code as input and produce code as output -- they don't see the runtime type of that code.
hmm, my macros are the few things in my app that I actually want to spec, because of their interface nature to my app. Yeh, I can ofc spec a presence/absence of an argument. Or spec a function that the macro calls... also a solution.
the latter is a good idea
keep in mind that macro specs are checked at compile time. so they can only check things you know at compile time.
they can't check things about the values, because the values don't exist yet
so macro specs are great for checking syntax (in core we use them for ns, defn, destructuring, etc) - things that are macros with their own syntax defined by the macro
function specs are checked (when instrumented) at runtime when you have values in hand
yup, so this makes total sense to me. I should keep it a habit to do as little work as possible in a macro, I only need the def on a symbol, and I can forward the rest to a function*
in general, having pairs like that is one common thing people do
with the caveat that the macro expands to a function call, so if you want that to be part of your public api, available outside the ns, then the function needs to be public too
sometimes that feels dirty
spec itself has this all over (s/and is a macro that expands to s/and-spec-impl etc)
we have significantly changed that in spec 2... but that's a longer story
yeh I see, it's dirty in a forgiveable way. Other plus is that when I'm working in the repl, I only need to change the function once (given that I have a `(def ~symbol function) pattern), instead of re-evaling all def instances
Hi! Never looked at how Spec works when it comes to data that depend on other data. Is it possible to use clojure.spec to validate and generate relational data? Let's say I have a map like this:
{:min-amount 100.00M
:max-amount 10000000.00M
:amount 133.00M}
:amount must be within the bounds of min-amount and max-amount.you can do this with custom generators
gen the min and the max and then use gen/bind to create a generator that produces values in the range and packages them all together
a tool in this area: https://github.com/reifyhealth/specmonstah
Yeah I am listening to a podcast about Specmonstah right now
Thanks @alexmiller I will look more into how custom generators work! 🙂
hey everyone, I want to spec a map with 2 values (`:key1` :key2
), they are both ints so ill use integer?
..
but the second key must be bigger than the first, whats the best way to achieve that?
@plins if you need more concrete guidance than that, LMK and I'll paste an example