Looking at the expansion in the macro stepper of 

1.
;; -----------------------------------------------
#lang racket/signature
(struct foo (bar))


2.
;; -----------------------------------------------
#lang racket
(define-signature foo^ ((struct foo (bar))))


It looks like in the first case a unit implementing the signature must define a 
`make-foo` constructor whereas in the second case a unit exporting the 
signature must define a `foo` constructor. 

I've tried looking at the implementation of  `racket/signature`, but I'm not 
sure exactly why this is happening, I think it might be because the wrong 
`struct` form may be used to build the list of names in the signature. If I 
change the first program to

;; -----------------------------------------------
#lang racket/signature
(require racket/base)
(struct foo (bar))

Then looking at the expansion seems to suggest a `foo` is expected in this case 
instead of the `make-foo` previously.


Dan


----- Original Message -----
From: "matthias" <matth...@ccs.neu.edu>
To: "Justin Zamora" <jus...@zamora.com>
Cc: "users" <users@racket-lang.org>
Sent: Wednesday, February 4, 2015 9:31:27 PM
Subject: Re: [racket] Problem with structs and #lang racket/signature

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
____________________
  Racket Users list:
  http://lists.racket-lang.org/users

Reply via email to