[racket] Confused about define-values(-for-export) forms in define-signature
On Apr 2, 2014, at 5:41 PM, Matthew Flatt wrote:
>>
>> What confuses me is that I can also define the following signature and unit:
>>
>> (define-signature y^
>> ((define-values (y) 5)))
>>
>> (define y@
>> (unit (import)
>> (export y^)))
>>
>> (define-values/invoke-unit y@ (import) (export y^))
>>
>> This does introduce a binding for y with the value 5, but I don't understand
>> why.
>
> A `define-values` in a signature adds a definition to any *importing*
> context (in contrast to `define-values-for-export` which adds a
> definition in any *exporting* context). The `define-values/invoke-unit`
> form "imports" the signature into the definition context.
>
>> Since the y^ signature is being exported instead of imported I expected
>> that the value of y should not be available in the y@ unit, and furthermore
>> there is no need to declare y in the signature as a variable which the unit
>> must define. So why is it the case that this unit defines and exports the value
>> of y, when according to the documentation this shouldn't happen.
>
> As you say, `y` isn't bound in the unit `y@` by the export of `y^`.
>
> With the `define-values/invoke-unit` form in the same context, though,
> the unit `y@` will be able to refer to `y`, just like any other binding
> in the unit's environment.
Dan, why don't you fix up the docs so that this issue is crystal clear to any future reader. Add examples -- Matthias