This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-08-31
Channels
- # announcements (1)
- # babashka (27)
- # beginners (107)
- # calva (2)
- # cider (1)
- # clara (1)
- # clj-kondo (17)
- # clojure (74)
- # clojure-europe (18)
- # clojure-nl (4)
- # clojure-norway (3)
- # clojure-spec (11)
- # clojure-uk (3)
- # clojurescript (10)
- # conjure (12)
- # datomic (4)
- # figwheel-main (1)
- # fulcro (28)
- # graalvm (11)
- # hugsql (12)
- # joker (1)
- # klipse (5)
- # malli (2)
- # meander (1)
- # membrane (9)
- # off-topic (26)
- # pedestal (6)
- # remote-jobs (1)
- # ring-swagger (5)
- # shadow-cljs (4)
- # test-check (14)
- # vrac (8)
- # xtdb (8)
@deadghost spec instrumentation/enforcement is opt-in at each call site. there’s not currently a way to spec all usages of a keyword in every map
IME instrumentation can be a big perf bottleneck. I rarely use it for my entire code base even during development
@deadghost Yeah, as @lilactown says, Spec is entirely opt-in by design and it is also intended more for boundaries than for "everything", so I think what you are asking for is a non-goal for Spec...
You can explicitly ask (s/valid? :foo/bar "1")
, you can s/instrument
a function with an appropriate Spec and then the call will check that, you can s/check
a function and have it check returned values against Specs. That's how it is designed.
Yeah that's reasonable. I don't think specing out the boundaries is too onerous but I'll see when I actually try to do it.
A lot of people make the mistake of treating Spec like some sort of "type system" (which it definitely is not) and trying "spec everything" which is a bad idea.
How do I write the specs for a function with map destructured arguments, e.g.,:
(defn budget-item-type
[{:transaction/keys [amount]}]
(if (ma/positive? amount) :expense :income))
(s/fdef budget-item-type
:args (s/keys* :req-un [::specs/money])
:ret #{:expense :income})
Thanks!destructuring really doesn't change how your spec something - from the function perspective you're just receiving a map
In this case here, your args spec is expecting a kwarg style sequence, not a map though. you either want the function to be a varargs (by using &) or to wrap your spec in s/cat.
Thanks @alexmiller!
Then it should probably be asked in that channel instead. :) Not many people in #clojure use Reagent.
In any case, your question is very vague. With how it's currently phrased, the only answer I can give is "you just do it".
when I try to run clojure
on windows, I get the following error:
PS C:<omitted>> clj
java.exe : Downloading: org/clojure/clojure/1.10.1/clojure-1.10.1.pom from central
At C:\<omitted>\Documents\WindowsPowerShell\Modules\ClojureTools\ClojureTools.psm1:304 char:5
+ & $JavaCmd -classpath $ToolsCp clojure.main -m clojure.tools.deps ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (Downloading: or...om from central:String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError
couldn't find any info on it here: https://github.com/clojure/tools.deps.alpha/wiki/clj-on-Windows
anyone in this channel who can help? 🙂 am on windows 10 server, running in powershell, openjdk 13you are not using powershell ISE by chance right?
No worries, ISE is meant to be used when writing powershell, it does some weird things with standard output of non-powershell commands (“native commands”)
I updated the docs 🙂 https://github.com/clojure/tools.deps.alpha/wiki/clj-on-Windows
How to process collection in parallel for side effects in clojure? EDIT: I got that temptation to use pmap, but i'm not interested what are the values of operation.
you could use run!
and have it launch future
s
that's basically an unconstrained number of jobs
in between that and pmap would be to use java executors with a thread pool and queue that constrains things however you like
https://cljdoc.org/d/metosin/spec-tools/0.10.4/doc/spec-coercion#spec-based-transformations anyone happen to know if this can transform the kw as well? For example, :foo/bar
-> :foo-bar
@U055NJ5CC can you point me to the right direction? Just to be clear :foo/bar 1
-> :foo-bar 1
.
Hi, my clojure backend needs to to call an external script (script.sh) and this works in development using (clojure.java.shell/sh "./script.sh" …) ,
(with the script located in project root dir), but when I run the production jar file inside my docker container, it is unable to locate the script. I’ve tried with the script next to the jar file, switching to an absolute path (inside the container) and more, but I keep getting Cannot run program "/script.sh": error=2, No such file or directory
I’ve verified that the script is actually inside the container and have also compared with another project where I have this working, but can’t seem spot the difference.
Help appreciated.
"/script.sh" seems like a clue - that looks like . (current directory) is being set to / in this case?
Doing a new attempt now with an absolute path. I can give an example from there when done
Still the same issue.
Error: Cannot run program "/app/script.sh": error=2, No such file or directory
When I log “ls” and “pwd” right above the sh-call, I see what I would expect to see:
pwd: {:exit 0, :out /app, :err }
ls: {:exit 0, :out app.jar log script.sh , :err }
I would imagine that just the filename without path gives Java some more room to search the class path, so lets see 🙂
what is the proper way to test if a var or local is a dereffable thing? (atom, ref, agent, promise, etc)
this is a file path, has nothing to do with classpath
(map #(instance? clojure.lang.IDeref %) [1 :a (atom 3)])
@cpmcdaniel
@alexmiller Thanks, for the clarification. I was “afraid” of that when I wrote it 🙂 I did not come to Clojure from Java…
unfortunately, I'm not sure what the issue is - maybe try running bash
with the script as an argument? does the script have a shebang at the top?
It might be an issue with the $PATH environment var being different when you run it --maybe some other file is the one that’s missing?
It is actually an Expect script named script.exp
and it has a shebang #!/usr/bin/expect -f
And I forgot to install Expect in the container.
/app # ./script.exp
sh: ./script.exp: not found
Not surprising, but adding RUN apk add expect
to my Dockerfile solved the issue.
Sorry about all the confusion. I believe my attempt at isolation the problem and removing irrelevant details was not actually helpful.
no worries ;)
Hi, I am trying to create a spec for data that works for both qualified and unqualified keys. Here is the spec. Am I doing it right, or is there a more idiomatic way to do it
(s/def :contact/id uuid?)
(s/def :contact/first-name string?)
(s/def :contact/last-name string?)
(s/def :contact/email string?)
(s/def ::contact-item
(s/keys
:req [:contact/id :contact/first-name :contact/last-name :contact/email]))
(s/def ::contact-item-un
(s/keys
:req-un [:contact/id :contact/first-name :contact/last-name :contact/email]))
(s/def ::contact
(s/or :qualified ::contact-item
:unqualified ::contact-item-un))
Seems ok to me
I guess I’d wonder if you could transform the data first to have one spec instead
@alexmiller that’s true but then I’d have to call that function everywhere I need to transform.
something like this, @deadghost
(require '[spec-tools.core :as st])
(require '[clojure.spec.alpha :as s])
(s/def ::my-keyword
(st/spec
{:spec simple-keyword?
:decode/string (fn [_ x] (keyword (str (namespace x) "-" (name x))))}))
(st/coerce
::my-keyword
:foo/bar
st/string-transformer)
; => :foo-bar
I'm interested in transforming the k
, not the v
. (s/def :my/keyword ...)
:my/keyword
-> :my-keyword
.
Looking at the code, spec-tools doesn't have an easy way to transform s/keys
keys, just s/map-of
keys. PR welcome, or you could look either https://github.com/wilkerlucio/spec-coerce or other spec coercion libs
in my experience, fighting the fight for a canonical representation inside your own program is worth the battle
One fight at a time. Frontend already expects JSON encoded :foo-bar
and not :foo/bar
and unqualified :biz
instead of :foo/biz
.
fwiw, I have a similar challenge in my project. I have a layer that converts between the inconsistent names that the UI expects in JSON and the consistent, qualified names that the backend uses
@U2845S9KL that's essentially the point I'm trying to reach. Currently I don't even have an explicit layer, the transformations are scattered throughout the code. After that I can push for more consistent frontend data.
Yep. That's the situation I was in a few weeks ago. It wasn't too hard to create the "compatibility layer" since I had complete control over it. I have not yet tried to push this out to the UI
^ for this case. I found this https://github.com/clj-commons/camel-snake-kebab library super helpful