[racket] Problem with structs and #lang racket/signature

From: Justin Zamora (justin at zamora.com)
Date: Wed Feb 4 22:47:31 EST 2015

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
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20150204/9089fe29/attachment-0001.html>

Posted on the users mailing list.