Re: [racket-users] Injecting local contracts for prefab constructors

2021-05-12 Thread David Storrs
If you're willing to accept a low tech solution, might I suggest this: $ perl -i.bak -lpe 's/\(foo/\(make-foo/g' *.rkt Also, I'll self-plug and point you towards this: #lang racket (require struct-plus-plus ) (struct++ foo ([a real?]) (#:omit-reflection) #:prefab) (define checked (foo++ #:a

Re: [racket-users] Injecting local contracts for prefab constructors

2021-05-10 Thread Sage Gerard
I hope so! That's what I understood option B to mean. I could adjust the define-message macro according to the info in Ryan and Phillip's attachments, but I'm not well-educated on trapping struct operations. Phillip: Your example and email gives me the impression that when you add a chaperone,

Re: [racket-users] Injecting local contracts for prefab constructors

2021-05-10 Thread Hendrik Boom
On Sun, May 09, 2021 at 10:23:34PM +, Sage Gerard wrote: > I have a project with 57 prefab structure types. I need to construct > instances using a local contract (module level contracts do not fit my needs > here). Since I cannot define guards, the solution is easy enough. > > (struct foo

Re: [racket-users] Injecting local contracts for prefab constructors

2021-05-09 Thread Sage Gerard
Almost forgot, just in case someone asks: I want to avoid checking for invariant violations when I print. That would entail checking a bunch of values in accumulated program output, where it would be awkward to do something non-printing related, let alone raise an error. When I am printing

Re: [racket-users] Injecting local contracts for prefab constructors

2021-05-09 Thread Sage Gerard
Of course, if you're okay with a longer email. Before that, thank you both for volunteering your time to code something out. I enjoyed running into a `define-module-boundary-contract` in the wild for the first time. I sometimes print output in a (read)able form because I like analyzing my logs.

Re: [racket-users] Injecting local contracts for prefab constructors

2021-05-09 Thread Philip McGrath
Here's another minimally-tested sample implementation. A more robust solution might try to chaperone the struct type, as well, to protect reflective access to the constructor—but I wonder if that really makes sense when you are working with prefab structs. If you can explain more about your

Re: [racket-users] Injecting local contracts for prefab constructors

2021-05-09 Thread Ryan Culpepper
I'm not clear on what constraints you're working under with respect to modules, but hopefully you can adapt this to your needs. One option is to use a combination of `define-module-boundary-contract` (or `define/contract`) and `define-match-expander` to bind a name that can be used as a

[racket-users] Injecting local contracts for prefab constructors

2021-05-09 Thread Sage Gerard
I have a project with 57 prefab structure types. I need to construct instances using a local contract (module level contracts do not fit my needs here). Since I cannot define guards, the solution is easy enough. (struct foo (num) #:prefab) (define/contract make-foo (-> real? foo?) foo)