Note, though, (having tried this) that putting a contract on the guard will
give you undesirable blame behavior unless you use any/c for all the domain
contracts as Matthias did. The guard must be able to accept all arguments,
so the server module will be blamed if a client calls the constructor with
values that violate the domain portion of the contract.

-Philip

On Thu, Jun 29, 2017 at 10:18 AM, David Storrs <david.sto...@gmail.com>
wrote:

>
>
> On Thu, Jun 29, 2017 at 9:50 AM, Matthias Felleisen <matth...@ccs.neu.edu>
> wrote:
>
>>
>> > On Jun 29, 2017, at 9:21 AM, David Storrs <david.sto...@gmail.com>
>> wrote:
>> >
>> > I'd like to create a new exception type, 'exn:fail:insufficient-space',
>> something like this:
>> >
>> > (struct exn:fail:insufficient-space exn:fail (requested available
>> source))
>> >
>> > I would like to do two things:
>> >
>> > 1) Make the exn-message field be standardized so that the person
>> throwing the exception doesn't need to (or, ideally, cannot) set it.
>> >
>> > 2) Apply a contract so that only valid arguments can be supplied.
>> >
>> > I could do both of these with a 'guard' statement and an external
>> function definition:
>> >
>> > (define/contract (zot msg ccm req avail src type)
>> >   (values "Insufficient space" ccm req avail src))
>> > (struct exn:fail:insufficient-space exn:fail (requested available
>> source)
>> >     #:guard zot)
>> >
>> > ...but this gives me a top-level definition that I don't want and need
>> to remember to not export.
>>
>>
>> I really think we should explicitly export bindings not implicitly.
>> (all-defined-out) is a kludge.
>>
>>
>> > I've been through the sections on contracts and local bindings and I
>> don't see a way to apply one to a raw lamdba -- is there one?
>>
>>
>> (struct exn:fail:insufficient-space exn:fail (requested available source)
>>   #:guard
>>   (local ((define/contract (zot msg   ccm   req   avail src   type)
>>             (-> any/c any/c any/c any/c any/c any/c (values string? any/c
>> any/c any/c any/c))
>>             (values "Insufficient space" ccm req avail src)))
>>     zot))
>>
>>
>>
> Brilliant.  Thanks, Matthias.
>
> --
> 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.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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.
For more options, visit https://groups.google.com/d/optout.

Reply via email to