[racket] define-values/invoke-unit not working when generated by a macro

From: Jay McCarthy (jay.mccarthy at gmail.com)
Date: Tue Aug 6 17:30:05 EDT 2013

The problem is that define-values/invoke-unit uses the lexical context
of its own syntax to associate the new identifiers with, so the new
identifiers aren't in the same context as the 'woof' use.

On Tue, Aug 6, 2013 at 3:11 PM, Nick Main <david.nick.main at gmail.com> wrote:
> I am attempting to write a macro to clean up the use of
> define-values/invoke-unit and finding some confusing behavior.
>
> My macros module is:
>
> #lang racket
> (provide (all-defined-out))
>
> (define-signature dog^
>   (woof
>    bark))
>
> (define mutt@
>   (unit
>     (import)
>     (export dog^)
>     (define (woof) (printf "Wuf !!\n"))
>     (define (bark) (printf "RarRarRar !!\n"))))
>
> (define-syntax use-dog
>   (syntax-rules ()
>     ([_ dog-unit]
>      (define-values/invoke-unit dog-unit
>        (import)
>        (export dog^)))))
>
>
> ..and the module using it is:
>
> #lang racket
> (require "macros.rkt")
>
> (define-values/invoke-unit mutt@
>   (import)
>   (export dog^))
>
> (use-dog mutt@)
>
> (woof)
> (woof)
> (bark)
> (woof)
>
>
> I am trying to make the "use-dog" macro expand to the equivalent
> define-values/invoke-unit form as shown.
> If I comment out the define-value/invoke-unit form I get warning about
> unbound identifier woof - implying that the (use-dog dog^) form is not doing
> the job. Moreover, the second module as it stands does not give a warning
> about duplicate definitions for woof or bark (as it does if I duplicate the
> define-values/invoke-unit form) - further indicating the non-action of
> use-dog.
>
> The macro stepper shows use-dog expand exactly as expected, but it then
> seems to be ignored without any warnings.
>
> Is there something I am misunderstanding here, or is this a bug ?
>
> ____________________
>   Racket Users list:
>   http://lists.racket-lang.org/users
>



-- 
Jay McCarthy <jay at cs.byu.edu>
Assistant Professor / Brigham Young University
http://faculty.cs.byu.edu/~jay

"The glory of God is Intelligence" - D&C 93

Posted on the users mailing list.