#lang racket
(module server racket
(provide
(contract-out
(fish%
(class/c
(update (->m degrees-of-freshness any/c))
(field [freshness degrees-of-freshness])))))
(define degrees-of-freshness
(one-of/c 'fresh 'frozen 'edible 'rotten))
(define fish%
(class object%
(super-new)
(field [freshness 'fresh])
;; set this object's freshness field to v
(define/public (update v) (set! freshness v)))))
(module client racket
(require (submod ".." server))
(define fish (new fish%))
(send fish update 'edible)
;; blow up if exn raised isn't contract failure
(with-handlers ([exn:fail:contract? void])
(send fish update 'done)
(raise 'catastrophe)))
(require 'client)
On Jun 21, 2015, at 5:41 AM, Aidan Gauland wrote:
> Say I want to define a flat contract for the "freshness" field of my
> fish class, so I define a contract for it like so:
>
> (define/contract fish-freshness/c
> (-> any/c
> boolean?)
> (flat-named-contract 'fish-freshness/c
> (lambda (x)
> (not (eq? #f (member x '(fresh frozen edible rotten)))))))
>
> Am I barking up the wrong tree here, or is this perfectly sensible?
>
> Regards,
> Aidan Gauland
>
> --
> 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 [email protected].
> 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 [email protected].
For more options, visit https://groups.google.com/d/optout.