This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-02-20
Channels
- # aleph (72)
- # announcements (13)
- # architecture (8)
- # aws (3)
- # babashka (110)
- # beginners (38)
- # calva (2)
- # clerk (1)
- # clojure (118)
- # clojure-austin (3)
- # clojure-dev (8)
- # clojure-europe (50)
- # clojure-france (2)
- # clojure-nl (1)
- # clojure-portugal (1)
- # clojure-uk (3)
- # clojurescript (101)
- # clr (10)
- # data-science (15)
- # datascript (5)
- # datomic (3)
- # events (1)
- # fulcro (22)
- # graalvm (2)
- # gratitude (3)
- # guix (1)
- # honeysql (1)
- # hyperfiddle (72)
- # jobs (3)
- # lsp (23)
- # malli (18)
- # membrane (29)
- # obb (1)
- # releases (1)
- # ring-swagger (2)
- # shadow-cljs (8)
- # squint (113)
- # xtdb (9)
I’d like to use the :validate
option of cli-tools parse-opts
however, I can’t seem to get it to work the way I’d like. I want to use the provided error message when the user neglects to provide the option:
(def cli-options
;; An option with a required argument
[["-s" "--source-name source-name"
:default nil
;; :default-fn #(str "XXXX" %)
;; :parse-fn #(str "XXX" %)
:validate [#(not (nil? %)) "--source-name source-name must be provided"]]
;; [nil "--source-region source-region"]
;; [nil "--target-name target-name"]
;; [nil "--target-name target-name"]
])
Is this possilbe? (it seems like validate doesn’t get called when it’s using the default value)Ooooooh :missing
keyword. It doesn’t show up in the docs here: https://clojure.github.io/tools.cli/
However I see it in my repl docs now.
Trying out Spec and had a really tricky exercise (for me) building on some of Programming Clojure by Alex Millar Stuart Halloway & Aaron Bedra. With a simple Ingredient map I had a scale function. I was looking at overflows which could be 'fixed' by subs ' for . But I tasked using Spec or {:pre conds} to limit valid input within *.
The Spec work for the function I found really hard. In the end it was only by re-reading several times the Guide To Spec on Clojure site that I realised the (s/and of :args in the s/fdef was tripping me up as the each part was using an active result from the first.
The section is 'Spec’ing functions' especially para 'The second :args
predicate takes as input... I don't if its me or if this description needs some highlighting or further exposition?
I include code snippet with comments as I thrashed out. But I also wondered if there was some REPL type process Ive missed which helps when working out Specs?
This also tripped me up initially. In addition I didn't understand (from reading code) that specs compose entirely bottom up. In a sense even if you don't specifically ask for them. Say you have an attribute spec of A, and a map spec (s/keys) for B. You don't specify in B that you use A (not even as an optional member), but when you validate B and have A in it with an invalid value, then B will be invalid. It makes sense if you try this in a REPL. And I think spec is well designed that way. But I initially didn't internalize this which tripped me up when reading code.
Thanks @U01EFUL1A8M. Yes and I wondered related to your B spec implies A spec example; I seemed to get spec error reports that only say B is faulty with no trace to the root A invalidity. I tried using libs like expound but not sure I know how to drive this spec 'stack' effect?
I am tripping on something simple, if I have map like this: {:temp 42.6, :dtof 217.0}
and I need to get a vector like this: [42.6 217.0]
using lambda inside a map, how can I do that. It seems like I should be able to do something like: (map #(vec (get % :temp) (get % :dtof)) raw-set)))
but it does not work.
oh you just have a single map? ((juxt :temp :dtof) {:temp 42.6 :dtof 217.0}
. Or just [(:temp m) (:dtof m)]
or even (map m [:temp :dtof])
(or mapv if you really want a vector)
OK, vals is perfect !!!
use one of @U11BV7MTK’s solutions like [(:temp m) (:dtof m)]
seems quite declarative
I tried it, but here is what I got:
The row-set
is a sequence of these maps.
Thats awesome, that seems to work.
it's not the only way, e.g.:
(map #(vector (:temp %) (:dtof %)) raw-set)
is what you're trying to do
#([(:temp %) (:dtof %)])
is invalid because the #
dispatch macro does not work like that, it's like trying to evaluate this: ([(:temp x) (:dtof x)])
vectors are callable of course in Clojure but this example is a) syntactically wrong (you're missing an argument in the call) and b) semantically wrong (your intent is not to call a vector but to build it)
Your original attempt: (map #(vec (get % :temp) (get % :dtof)) raw-set)))
was also wrong because you need vector
instead of vec
(`vec` works on a collection but vector
is variadic, it builds a vector from its individual elements)
OK, wow, I was wondering, I thought vec == vector, good explanation.
For reference:
user=> (read-string "#([(:temp %) (:dtof %)])")
(fn* [p1__196#] ([(:temp p1__196#) (:dtof p1__196#)]))
user=> (read-string "(fn [m] [(:temp m) (:dtof m)])")
(fn [m] [(:temp m) (:dtof m)])
> OK, wow, I was wondering, I thought vec == vector, good explanation. @U012GN57FJ9 Most IDEs let you see the signature of the function the cursor is at, consider enabling this feature in yours. It's really useful, especially as you're learning the language
Bit of a weird issue... The output of clj -Spath
and clj -Stree
seems to reference stuff that is out of date (ie. perhaps cached from an old version of the project's deps.edn
). Running clj -Mmy-alias
also seems to be ignoring my jvm-opts
. Invoking cider-jack-in
and everything works as expected (despite saying that it's using the exact same arguments that I am running from my shell). I've tried rm -rf .cpcache/
but stuff just comes back still referencing the old versions. Any tips on other places the cache could be (checked all the locations mentioned in https://clojure.org/reference/deps_and_cli#_classpath_caching) or how I could debug this further?
-Sforce
also results in the same output being generated (ie. referencing old versions that have since been updated)
there's nothing else cached anywhere for your classpath calculation, so I assume it's actually calculating it differently. presuming it's not something in your ~/.clojure/deps.edn, it would be useful to have the deps.edn and Clojure CLI version you're using, and a more precise description of what seems wrong to diagnose
if you can't share the deps.edn, then sharing the -Stree (or -Strace trace.edn) would be a good substitute
I tried using -Srepro
to try and rule out the ~/.clojure
stuff
DM'ing a few things (can't post publicly, but hoping it helps)
Figured it out, was my fault. Sorry to waste your time.