To add a bit to what Alexis said about flat contracts:

On Wed, May 22, 2019 at 1:23 PM Alexis King <lexi.lam...@gmail.com> wrote:

> Your intuition is right, but let me make it more precise: foo? is used
> when something is a flat contract, and foo/c is used otherwise. Flat
> contracts only check *first order properties* of values, which is a
> technical term that captures what you mean by “general nature.”
>
> The important distinction is that first order properties can be checked
> immediately … Since flat contracts only perform first-order checks, a flat
> contract can be used as a predicate, so you can write (foo? x) to get back
> a boolean. Likewise, all predicates can be used as flat contracts.
>

Some flat contracts use the foo/c naming convention when they include
special error reporting, which can potentially involve a performance cost
beyond a simple predicate. For example, the `xml` module provides both
`xexpr?` and `xexpr/c`:
https://docs.racket-lang.org/xml/index.html#(def._((lib._xml%2Fprivate%2Fxexpr-core..rkt)._xexpr%2Fc))
I write a lot of these kinds of contracts, and I think they're very
effective. In my RacketCon talk last year, I discussed using contracts to
do XML validation and produce error messages good enough for
non-programmers to fix invalid XML files:
https://youtu.be/pv0lLciMI24?t=5479

-Philip

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CAH3z3gYGGmxaNGJgVFG8y%3Dum2whn-LBj9-Q2vOHeem_cvANzAg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to