This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-06-05
Channels
- # beginners (135)
- # cider (30)
- # clara (66)
- # cljs-dev (18)
- # cljsrn (6)
- # clojure (115)
- # clojure-austin (1)
- # clojure-dev (10)
- # clojure-italy (7)
- # clojure-nl (1)
- # clojure-spec (18)
- # clojure-uk (26)
- # clojurescript (76)
- # cursive (2)
- # datomic (4)
- # devops (1)
- # emacs (19)
- # fulcro (159)
- # garden (3)
- # klipse (5)
- # leiningen (5)
- # off-topic (61)
- # om (7)
- # pedestal (6)
- # re-frame (17)
- # reagent (73)
- # ring-swagger (6)
- # rum (5)
- # shadow-cljs (60)
- # spacemacs (31)
- # specter (4)
- # vim (8)
- # yada (1)
Hi. I plan to try to use spec for auto-completion. Has it been done before?
Are the specs easy to parse /navigate programmatically?
@U8MJBRSR5 lot of parsers in 3rd party libs, using s/form
. As a sample, one parser and a spec visitor in spec-tools (https://github.com/metosin/spec-tools).
Also a issue to have a spec walker in the core: https://dev.clojure.org/jira/browse/CLJ-2251
thank you
… I think that s/explain-data
does a lot already.
Is there some kind of s/seq-of
operator, or a way to build it?
The idea is to act as a bridge to spec the chars in a string from the string itself: (s/conform (s/seq-of char?) "abc")
I don’t have a running repl atm, but I think you can use (coll-of char? :kind string?)
It works, thanks. Need to add :into []
to keep the chars order at conform time.
I still have trouble afterward … I would like to run some regex spec (e.g. s/cat
) on the content of a string but without having to apply s/conform
on the seq
of that string. I don’t know if it is possible.
FWIW, the general advice I’ve seen is that spec is not a great fit for parsing strings. Certainly people have done it by turning the string into a sequence with seq
, but often people run into further issues. More detail in comments here: https://www.reddit.com/r/Clojure/comments/7vwpu4/parsing_with_clojurespec/
TL;DR : https://clojuredocs.org/clojure.spec.alpha/conformer …with a nice example under the documentation.
A good discussion of pitfalls with conformers and how to work around them: https://groups.google.com/d/msg/clojure/Tdb3ksDeVnU/LAdniiZNAgAJ
“we recommend that you not use conformers for coercion. Conformers were added primarily as a tool for building custom composite spec types”
I know people have had success with using spec for parsing strings, just wanted to make you aware of possible issues down the road 🙂
if you run into them, it may be worth looking at something like https://github.com/cgrand/regex