Thanks Robby! -J

On Tue, Jan 3, 2017 at 8:58 AM, Robby Findler <ro...@eecs.northwestern.edu>
wrote:

> There may be a way to do this without it, but I've just pushed a
> change to define-module-boundary-contract that lets you specify the
> name that you want in the error message.
>
> Also, if you can use a `let`, that's probably better than
> procedure-rename, eg:
>
> (define make-bar
>   (let ([bar (λ (x [y 1] [z 1])
>                (bar x y z))])
>     bar))
>
> (It won't matter unless you call `bar` a lot.)
>
> Robby
>
>
> On Mon, Jan 2, 2017 at 1:25 PM, Jon Zeppieri <zeppi...@gmail.com> wrote:
> > Over time I've run into a number of problems trying to provide custom
> struct
> > constructors and match expanders under the same name, while also
> attaching
> > module-level contracts to the constructors. I've figured out most of the
> > issues (I think), but one remains. Here's an example:
> >
> > ===
> > #lang racket/base
> >
> > (module foo racket/base
> >   (require racket/contract
> >            racket/match
> >            (for-syntax racket/base
> >                        syntax/transformer))
> >
> >   (struct bar (x y z))
> >
> >   (define make-bar
> >     (procedure-rename
> >      (λ (x [y 1] [z 1])
> >        (bar x y z))
> >      'bar))
> >
> >   (define-module-boundary-contract
> >     make-bar*
> >     make-bar
> >     (->i ([x exact-integer?])
> >          ([y (integer-in 0 200)]
> >           [z (x y) (integer-in x y)])
> >          [result bar?]))
> >
> >   (define-match-expander make-bar**
> >     (syntax-rules ()
> >       [(_ x y z) (bar x y z)])
> >     (make-variable-like-transformer #'make-bar*))
> >
> >   (provide (rename-out [make-bar** bar])))
> >
> >
> > (require 'foo)
> >
> > (bar "hello")
> > ===
> >
> > The submodule here provides the name `bar` which doubles as a custom
> > constructor and a match-expander. And it works fine. The constructor's
> > contract has the right boundary, too. However, the contract violation
> uses
> > the wrong name for the constructor:
> >
> > ../../Applications/Racket
> > v6.7/collects/racket/contract/private/blame.rkt:159:0: make-bar*:
> contract
> > violation
> >   expected: exact-integer?
> >   given: "hello"
> >   in: the x argument of
> >       (->i
> >        ((x exact-integer?))
> >        ((y (integer-in 0 200))
> >         (z (x y) (integer-in x y)))
> >        (result bar?))
> >   contract from: (anonymous-module foo)
> >   blaming: anonymous-module
> >    (assuming the contract is correct)
> >   at: unsaved-editor:17.2
> >
> > It's calling the procedure `make-bar*`, which is the internal name,
> instead
> > of `bar`, the public name. Is there a way to get it to use the right
> name?
> >
> > I could name the struct type itself something other than `bar`, which
> would
> > free up that name to be used internally. I've taken that approach in the
> > past, in fact, but there are a number of places where I need to be
> vigilant
> > about names crossing the public/private boundary (notice the use of
> > `procedure-rename` in the above example; without it, `bar` will evaluate
> --
> > in a public context -- to a procedure named `make-bar`, which is
> awkward),
> > and so starting with the public names seems to minimize the number of
> > problems.
> >
> > Any thoughts?
> >
> > - Jon
> >
> > --
> > 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