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

From: Matthias Felleisen (matthias at ccs.neu.edu)
Date: Wed Feb 4 21:31:27 EST 2015

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



Posted on the users mailing list.