[racket] How to make unit signature macros take prefix into account

From: Carl Eastlund (cce at ccs.neu.edu)
Date: Wed Aug 7 22:21:27 EDT 2013

Nick,

You can't just go by the immediate expansion.  Lots of temporary names are
bound by forms like define-values/invoke-unit; it binds an internal alias
called msg-chan-subscribe that should be defined as a rename transformer
for diagrammsg-chan-subscribe.  Can you give a full example the rest of us
can look at, and perhaps illustrate what incorrect runtime behavior is
caused by this problem?  That will be more telling than just the textual
name from expansion, because identifiers carry a lot of "invisible" data
about their bindings.

Carl Eastlund


On Wed, Aug 7, 2013 at 10:00 PM, Nick Main <david.nick.main at gmail.com>wrote:

> I have a signature that includes a macro to clean up the use of one of the
> procs in the signature.
>
> Two different units with the same signature are used
> via define-values/invoke-unit - the second one uses a prefix in the export
> sig-spec to differentiate it from the first.
> The macro introduced by the second use does not refer to the other proc
> using the prefix.
>
> The concrete example:
>
> ;; Signature of a message channel
> (define-signature message-channel^
>   (
>    ;; ...
>    msg-chan-subscribe   ; ( (msg -> boolean) first? -> thunk)
>
>    ;; Enqueue message(s) for a channel at normal priority
>    <--   ; ( msg .. -> void )
>
>    ;; Enqueue message(s) for a channel at high priority
>    <++   ; ( msg .. -> void )
>
>    ;; Macro to create a message handler.
>    ;; ...
>    (define-syntaxes (==>)
>      (syntax-rules (msg)
>        [(_ match-body ...) (msg-chan-subscribe
>                             (λ(msg)
>                               (syntax-parameterize
>                                ([the-message (make-rename-transformer
> #'msg)])
>                                (match msg
>                                  match-body ...
>                                  [_ #t])))
>                             #f)]))))
>
>
> When (define-values/invoke-unit <some-unit> (import) (export (prefix
> diagram message-channel^))) is used it introduces the bindings diagram<-- ,
> diagram<++ , diagrammsg-chan-subscribe and diagram==> .
>
> The form
>
> (diagram==>
>    .. message handlers ..)
>
> expands to (msg-chan-subscribe ...) rather than (diagrammsg-chan-subscribe
> ...) - and thus it listens to the first (wrong) message channel.
>
> Is there any way to make macros defined in signatures be aware of the
> prefix used with the signature ?
>
> ____________________
>   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/20130807/5b8f595c/attachment-0001.html>

Posted on the users mailing list.