clojure-spec

About: http://clojure.org/about/spec Guide: http://clojure.org/guides/spec API: https://clojure.github.io/spec.alpha/clojure.spec.alpha-api.html
johnjelinek 2020-10-14T02:56:13.106400Z

question regarding preference: do you add your specs to an existing namespace of a domain model or do you have a separate spec namespace to share your specs around?

seancorfield 2020-10-14T03:07:45.106900Z

@johnjelinek Here's how we organize the different types of specs we write https://corfield.org/blog/2019/09/13/using-spec/

1šŸ‘
vlaaad 2020-10-14T05:14:35.107100Z

Oh, sorry, I added threading in the message for readability, actual spec doesn't have it

vlaaad 2020-10-14T05:33:19.107300Z

Thanks, I'll try that

vlaaad 2020-10-14T07:04:40.107500Z

It did help, thank you!

Ivan Fedorov 2020-10-14T15:49:37.109200Z

so, how safe is it to use s/conform as a regex matcher? As in https://juxt.pro/blog/parsing-with-clojure-spec

(s/def ::contentline
  (s/cat
    :name ::iana-token
    :params (s/*
              (s/cat
                :semi #{\;}
                :param-name ::iana-token
                :equals #{\=}
                :param-value ::iana-token))
    :colon #{\:}
    :value ::iana-token))

(s/conform
  ::contentline
  (seq "DTSTART;TZID=US-EAST:20180116T140000"))
=>
{:name [\D \T \S \T \A \R \T],
 :params
 [{:semi \;,
   :param-name [\T \Z \I \D],
   :equals \=,
   :param-value [\U \S \- \E \A \S \T]}],
 :colon \:,
 :value [\2 \0 \1 \8 \0 \1 \1 \6 \T \1 \4 \0 \0 \0 \0]}

(apply str (get-in ā€¦ [:params 0 :param-value]))
=> "US-EAST"

Ivan Fedorov 2020-10-14T15:51:24.109900Z

Thinking about using it to parse recurrence rule from RFC5545 https://icalendar.org/iCalendar-RFC-5545/3-3-10-recurrence-rule.html

2020-10-14T16:02:33.110400Z

spec isn't designed for string parsing -- I've seen people recommend instaparse: (alex miller on the topic) https://www.reddit.com/r/Clojure/comments/fx5ko1/parser_libraries/fmttmzy/?utm_source=amp&utm_medium=

Ivan Fedorov 2020-10-14T16:04:32.110700Z

Thanks @uwo!

kenny 2020-10-14T16:07:08.110900Z

šŸ˜¢

kenny 2020-10-14T16:07:09.111100Z

https://clojure.atlassian.net/browse/CLJ-2095

Ivan Fedorov 2020-10-14T16:10:00.111300Z

I think Iā€™m not that interested in performance here, more interested in how stable the implementation will be.

1šŸ¤˜
alexmiller 2020-10-14T17:14:37.111800Z

we do not recommend using regex specs to parse strings

1šŸ‘