This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-03-16
Channels
- # aws-lambda (3)
- # beginners (20)
- # boot (201)
- # cljs-dev (45)
- # cljsrn (9)
- # clojars (19)
- # clojure (141)
- # clojure-china (2)
- # clojure-dev (11)
- # clojure-greece (6)
- # clojure-italy (1)
- # clojure-new-zealand (1)
- # clojure-romania (1)
- # clojure-russia (55)
- # clojure-spec (58)
- # clojure-taiwan (1)
- # clojure-uk (97)
- # clojure-ukraine (40)
- # clojurescript (77)
- # core-async (5)
- # core-typed (1)
- # cursive (35)
- # datomic (9)
- # jobs (2)
- # jobs-rus (25)
- # juxt (8)
- # lein-figwheel (14)
- # luminus (24)
- # mount (16)
- # off-topic (56)
- # om (36)
- # onyx (22)
- # pedestal (3)
- # perun (14)
- # re-frame (111)
- # reagent (5)
- # remote-jobs (6)
- # ring-swagger (3)
- # slack-help (1)
- # specter (17)
- # unrepl (12)
- # untangled (56)
What's a good way to spec a sequence with a static subsequence? For example, if I want to spec a seq that contains 1, 2, 3
somewhere in the middle, is there a better way to do it than the following?
(s/conform (s/cat :pre (s/+ any?)
:one-two-three (s/& (s/+ any?) #(= [1 2 3] %))
:post (s/+ any?))
[:foo :bar 1 2 3 :baz :qux])
This works, but it feels like I'm abusing s/&
.@english doesn’t seem like you need the s/&
at all
(s/conform (s/cat :pre (s/+ any?)
:one-two-three (s/cat :1 #{1} :2 #{2} :3 #{3})
:post (s/+ any?))
[:foo :bar 1 2 3 :baz :qux])
not very pretty, but that should work a little more directly
it will gen automatically too whereas the prior one will not
I started writing a Language Server for Clojure(Script) https://github.com/thheller/shadow-devtools/issues/2
https://cloud.githubusercontent.com/assets/144930/23987578/8b4bb1fa-0a2a-11e7-8bfb-7caa0b77dcc8.png
ie. if I have (defn x :foo)
in a file or REPL I get an exception with Call to clojure.core/defn did not conform to spec
and ex-data
containing the usual information
that information however is not enough for me to provide good highlighting for the error that occurred since it contains no source information
the question is whether or not this is something the error should/could contain or not? I imagine all tools will require it somehow as the given exception doesn't tell you anything about the actual location of the error.
@alexmiller you said you were looking into the error presentation details a while back, any progress on that?
found :clojure.spec/args
but neither that list or the items in there contain any meta
data from the reader
is it possible to use spec to generatively test stateful fns? for example, if I have a fn that takes an in
and out
core.async channel, where it performs some logic on the values in the in
channel (when they show up in the future), and perhaps puts values on the out
channel, can I generate any meaningful tests?
There are a few attempts it seems: https://goo.gl/DLEA1K https://goo.gl/F9E4nl https://goo.gl/ESiLvz https://goo.gl/J5lKY4 and a neat resource from an Erlang implementation: https://goo.gl/lrnFB4 , but I’ve been unable to dig up any recent available libs or discussions on the matter
@thheller yeah I made some progress on it but got blocked by not having access to the root value in the explain-data. I have a ticket and patch pending about that and had a brief conversation about it with Rich last week. I believe there is a separate ticket re spec source meta, certainly there is some overlap with the idea of spec doc meta.
@alexmiller ah thx, found the JIRA issue. will try with the patch and see if I can do what I have in mind.
maybe this catch https://github.com/clojure/clojure/blob/2ff700ede3866f97d7b1f53342e201df94384aee/src/jvm/clojure/lang/Compiler.java#L6820
hmm, it used to but I think when macroexpand-check was refactored this didn’t get changed along with it
macroexpand-check used to throw IllegalArg
I will take a look at that
https://github.com/clojure/clojure/commit/b3d3a5d6ff0a2f435bb6a5326da2b960038adad4
should have been changed with this commit
that’s definitely a bug
so that happened in 1.9.0-alpha12
@alexmiller maybe we could add the last known form
to CompilerException(String source, int line, int column, Throwable cause, Object form)
as well
I’ll look at that
oh, that’s not there already. that needs to be a separate idea then.
that needs some thought. when you’re throwing arbitrary data like that you can introduce some weird problems
I have been burned by that a number of times over the years
I hate that the only exception in Clojure that can attach location info is CompilerException… grr
hehe a 2nd constructor adding the form where possible seems like the simplest non-breaking change
not sure how the CLJ compiler/reader is implemented but if the form contains lazy things that will indead cause strange errors
I will attempt to port the clojure.core.specs
over to CLJS soon, it would be amazing if the exceptions generated on errors where somewhat similar
well when you have a form, it’s been read and should not be lazy (unless perhaps it was generated by a prior macro?)
do you really want the form or do you want a string representation of the form?
yeah, that’s what I was wondering
I have never actually worked with the Clojure analyzer, only the tools.analyzer or cljs.analyzer. so I need to figure out how the CLJ metadata looks
well, nothing in this area is going to change quickly :)
hehe no doubt but the change to CompilerException
is simple enough that I can try in a branch
please add info to http://dev.clojure.org/jira/browse/CLJ-2129 if you obtain some
forms can be very large, at the repl you just type (/ 1 0) and that fails, and it seems like a good idea to report the form, but I really have no need to see the macroexpansion of a 100 line go block
Say, is there any way to get (s/keys)
to validate a map with non-namespaced keywords? Trying to add some validation around an external library I don't control
Oh, sorry, just noticed the section in the guide around :req-un
, will read that more carefully