[racket] Problem with structs and #lang racket/signature
Yes, it appears that `racket/signature` exports a `struct` that is
consistent with `define-struct` instead of `struct`.
I'm not sure whether that was a bug that didn't get caught, or whether
it was intentional (for some kind of compatibility) and was documented
incorrectly. My guess is that it was the former, originally; at this
point, it has to be the latter, since I don't want to break code that's
using `racket/signature`. So, I'll fix the documentation.
At Wed, 4 Feb 2015 22:47:31 -0500, Justin Zamora wrote:
> Yes, I had a copy/paste error in my previous message. The struct definition
> in the unit matches the one in the signature. I think that Daniel
> identified the core problem that the constructor is defined differently in
> #lang racket/signature.
>
> Justin
> On Feb 4, 2015 9:31 PM, "Matthias Felleisen" <matthias at ccs.neu.edu> wrote:
>
> >
> > This works:
> >
> > ;; ---------------------------------------------------------
> > #lang racket/signature ;; b-sig.rkt
> >
> > (struct spelling-word (word sentence word-number lesson word-list))
> > b-value
> >
> > ;; ---------------------------------------------------------
> > #lang racket/unit ;; b-unit.rkt
> >
> > (require "b-sig.rkt")
> >
> > (import)
> > (export b^)
> >
> > (define-struct spelling-word (word sentence word-number lesson word-list))
> >
> > (define b-value 3)
> >
> >
> > ;; ---------------------------------------------------------
> > The signature of a component (unit) describes the names of the exports
> > (or imports). So when you write
> >
> > (struct my-struct (a b c))
> >
> > in a signature, your exporting unit must define something like
> >
> > (define-struct my-struct (a b c))
> >
> > [You can also use the struct syntax but you then need to define the
> > alternative constructor.]
> >
> > ;; ---------------------------------------------------------
> > I recommend developing small units in one DrRacket buffer. It's the
> > easiest way to get used to their syntax.
> >
> > -- Matthias
> >
> >
> >
> >
> >
> >
> >
> > On Feb 4, 2015, at 9:14 PM, Justin Zamora wrote:
> >
> > > There seems to be a problem exporting struct constructors when using
> > #lang racket/signature. This works:
> > >
> > > ----- b-sig.rkt-----
> > > #lang racket
> > >
> > > (define-signature b^
> > > ((struct my-struct (a b c))
> > > b-value))
> > >
> > > (provide b^)
> > >
> > > ----- b-unit.rkt -----
> > > #lang racket/unit
> > >
> > > (require "b-sig.rkt")
> > >
> > > (import)
> > > (export b^)
> > >
> > > (struct spelling-word
> > > (word sentence word-number lesson word-list))
> > >
> > > (define b-value 3)
> > >
> > > But if you change b-sig to use #lang racket/signature:
> > > #lang racket/signature
> > >
> > > (struct my-struct (a b c))
> > > b-value
> > >
> > > then running b-unit produces the error:
> > >
> > > Welcome to DrRacket, version 6.1 [3m].
> > > Language: racket/unit; memory limit: 512 MB.
> > > define-unit: undefined export make-my-struct in: (define-unit b@
> > (import) (export b^) (struct my-struct (a b c)) (define b-value 3))
> > >
> > > Is this a just a bug or am I missing something?
> > >
> > > ____________________
> > > Racket Users list:
> > > http://lists.racket-lang.org/users
> >
> >
> ____________________
> Racket Users list:
> http://lists.racket-lang.org/users