> On Nov 4, 2016, at 4:58 PM, Sam Tobin-Hochstadt <sa...@cs.indiana.edu> wrote: > > Here's an example:
Oh, so this only raises an error when creating an *instance* of y, not when creating the struct-type for y. Is there any way to make it raise an error on the make-struct-type call? Alex Knauth > #lang racket > > (define (make-final-struct-type name count) > (define-values (type constructor predicate accessor mutator) > (make-struct-type name #f count 0)) > (values (chaperone-struct-type type (λ _ (error 'fail1)) > (λ _ (error 'fail2)) > (λ _ (error 'fail3))) > constructor predicate accessor mutator)) > > (define-values (struct:x make-x x? x-ref x-set!) > (make-final-struct-type 'x 2)) > > (define-values (struct:y make-y y? y-ref y-set!) > (make-struct-type 'y struct:x 0 0)) > > (make-x 0 0) > (make-y 0 0) > > Sam > > On Fri, Nov 4, 2016 at 4:54 PM, Sam Tobin-Hochstadt > <sa...@cs.indiana.edu> wrote: >> Look at `chaperone-struct-type`: >> http://docs.racket-lang.org/reference/chaperones.html?q=chaperone-struct-type#%28def._%28%28quote._~23~25kernel%29._chaperone-struct-type%29%29 >> >> You can just have the guard always error. >> >> Sam >> >> On Fri, Nov 4, 2016 at 4:49 PM, Alex Knauth <alexan...@knauth.org> wrote: >>> >>>> On Nov 4, 2016, at 4:43 PM, Sam Tobin-Hochstadt <sa...@cs.indiana.edu> >>>> wrote: >>>> >>>> Typed Racket chaperones the struct type to prevent further extension. >>> >>> Ok, thanks. Where would I go to see how I would create a chaperone like >>> this? >>> >>>> Sam >>>> >>>> On Fri, Nov 4, 2016 at 4:29 PM, Alex Knauth <alexan...@knauth.org> wrote: >>>>> Hello, >>>>> >>>>> Is there a way to enforce that a particular struct is final, in other >>>>> words, that no one can declare a sub-struct of it? >>>>> >>>>> (struct foo (a b c) #:final) >>>>> >>>>> (struct bar foo (d e f)) >>>>> ; should produce a syntax error similar to: >>>>> ; struct: cannot inherit from the final struct foo >>>>> >>>>> (make-struct-type 'bar struct:foo 3 0) >>>>> ; should produce an error at runtime: >>>>> ; make-struct-type: cannot inherit from the final struct foo >>>>> >>>>> Does struct have a feature like this? If I'm remembering correctly, Typed >>>>> Racket does something to make sure that untyped structs can't inherit >>>>> from typed structs. What does Typed Racket do to do do that? >>>>> >>>>> Alex Knauth >>>>> >>>>> -- >>>>> 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. > > -- > 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.