I answered my own question in the specific case, this seems to work:

(defn to-int
  [x]
  (try
    (Long/parseLong x)
    (catch Exception _
        nil)))

(s/def ::intable (s/conformer to-int))

(s/conform (s/cat :ints ::intable) ["5"])
> {:ints 5}

On Wed, May 25, 2016 at 8:36 AM Gary Trakhman <gary.trakh...@gmail.com>
wrote:

> Is there a public way to get the registry's spec at a keyword?  I can
> envision other libs being built around the spec registry, and I'm trying to
> write a small one (coercions) to see if I can use spec for this use-case.
> Is that non-sanctioned kind of thing going forward?
>
> The likely candidate seems 'specize'.
>
> On Wed, May 25, 2016 at 8:30 AM Rich Hickey <richhic...@gmail.com> wrote:
>
>> > Would you ever expect to use fdef/instrument active in production for
>> validation
>>
>> No, definitely not. It’s that kind of runtime checking (and expense) that
>> gives some dynamic lang checking systems a bad rep.
>>
>> The philosophy is - generative testing has made sure your function
>> complies with the specs. So, testing the :ret and :fn properties over and
>> over is redundant and serves no point.
>>
>> OTOH, you may encounter user- or externally-supplied data at runtime and
>> want to use the facilities of spec to validate/process it. Then you can use
>> valid? or conform *explicitly* to do so.
>>
>> The intent is that running with wrappers (instrumentation) should be done
>> only during testing.
>>
>> > On May 24, 2016, at 7:43 PM, Elliot <ell...@deck36.net> wrote:
>> >
>> > Super super excited for this feature, thanks so much for creating this.
>> >
>> > In the runtime-validation case, the guide mentions:
>> >
>> > 1. Calling `valid?` in a precondition
>> > 2. Calling `conform` in the fn implementation
>> >
>> > However neither of these appear to use the `fdef`/`instrument` combo,
>> which seems the closest to "type annotating" the function.  Would you ever
>> expect to use fdef/instrument active in production for validation, or is
>> that a misunderstanding of its use?
>> >
>> > Thanks!
>> >
>> > - E
>> >
>> >
>> > On Tuesday, May 24, 2016 at 11:12:59 AM UTC-7, scott stackelhouse wrote:
>> > I restructured my data to make this section an optional sub-map, which
>> I think is actually better anyway.
>> >
>> > On Tuesday, May 24, 2016 at 11:08:27 AM UTC-7, scott stackelhouse wrote:
>> > Ok.
>> >
>> > Thanks all who have worked on this, btw.  It is incredibly timely for
>> me and is already great help for a work project.
>> >
>> > --Scott
>> >
>> > On Tuesday, May 24, 2016 at 10:57:26 AM UTC-7, Rich Hickey wrote:
>> > ‘and' and ‘or’ are not currently supported in :opt
>> >
>> >
>> > > On May 24, 2016, at 1:45 PM, scott stackelhouse <
>> scott.sta...@gmail.com> wrote:
>> > >
>> > > I'm having a problem writing a spec for a map with some required
>> keywords and some optional keywords.  The caveat here is that the optional
>> keywords are all or none... that is they are optional but if one is present
>> they must all be present.
>> > >
>> > > What I tried to write was:
>> > >
>> > > (s/keys :req [::a ::b ::c] :opt [(and ::d ::e ::f)])
>> > >
>> > > and that fails an assertion.  It appears that the logicals (and, or)
>> are not allowed in the optional section?
>> > >
>> > > Am I thinking about this in the wrong way?
>> > >
>> > > --Scott
>> > >
>> > > --
>> > > You received this message because you are subscribed to the Google
>> > > Groups "Clojure" group.
>> > > To post to this group, send email to clo...@googlegroups.com
>> > > Note that posts from new members are moderated - please be patient
>> with your first post.
>> > > To unsubscribe from this group, send email to
>> > > clojure+u...@googlegroups.com
>> > > For more options, visit this group at
>> > > http://groups.google.com/group/clojure?hl=en
>> > > ---
>> > > You received this message because you are subscribed to the Google
>> Groups "Clojure" group.
>> > > To unsubscribe from this group and stop receiving emails from it,
>> send an email to clojure+u...@googlegroups.com.
>> > > For more options, visit https://groups.google.com/d/optout.
>> >
>> >
>> > --
>> > You received this message because you are subscribed to the Google
>> > Groups "Clojure" group.
>> > To post to this group, send email to clojure@googlegroups.com
>> > Note that posts from new members are moderated - please be patient with
>> your first post.
>> > To unsubscribe from this group, send email to
>> > clojure+unsubscr...@googlegroups.com
>> > For more options, visit this group at
>> > http://groups.google.com/group/clojure?hl=en
>> > ---
>> > You received this message because you are subscribed to the Google
>> Groups "Clojure" group.
>> > To unsubscribe from this group and stop receiving emails from it, send
>> an email to clojure+unsubscr...@googlegroups.com.
>> > For more options, visit https://groups.google.com/d/optout.
>>
>> --
>> You received this message because you are subscribed to the Google
>> Groups "Clojure" group.
>> To post to this group, send email to clojure@googlegroups.com
>> Note that posts from new members are moderated - please be patient with
>> your first post.
>> To unsubscribe from this group, send email to
>> clojure+unsubscr...@googlegroups.com
>> For more options, visit this group at
>> http://groups.google.com/group/clojure?hl=en
>> ---
>> You received this message because you are subscribed to the Google Groups
>> "Clojure" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to clojure+unsubscr...@googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.
>>
>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to