[racket-dev] define-struct exports something to BSL

From: Michael Sperber (sperber at deinprogramm.de)
Date: Wed Sep 22 02:50:20 EDT 2010

Nadeem Abdul Hamid <nadeem at acm.org> writes:

> Consider a beginner file with:
>    (define-struct boa (name length))
>
> Student writes a template/function with parameter named "a-boa", but
> misspells one occurrence, writing "boa" instead of "a-boa".
>
> (define (feed a-boa)
>   (make-boa (boa-name a-boa)
>             (boa-length boa)))
>
> Their tests then fail at runtime with:
>    boa-length: expects argument of type <struct:boa>; given (make-signature ...)
>
> Why is "boa" as a type visible at all in the student languages? The
> make-signature thing is really confusing, because they recognize it as
> something like a constructor but they don't know what structure it
> corresponds to.

This is my fault: We're working on something called "signatures", which
can take the place of a contract comment, but is instead checked by the
system.  For example, one could write for the functions above:

(: make-boa (string number -> boa))
(: boa-name (boa -> string))
(: boa-length (boa -> number))
(: feed (boa -> boa))
         ^^^

This is why `boa' is available, and why you get output identifying "boa"
as a signature.  (Before the introduction of signatures, it would say
"illegal use of syntax" - I'm not sure that's much better.)

The work on signatures is not quite done yet (and undocumented ...), but
we're working hard on completing it in the near future.

-- 
Cheers =8-} Mike
Friede, Völkerverständigung und überhaupt blabla


Posted on the dev mailing list.