[racket] overriding unit functions with other units

From: Todd O'Bryan (toddobryan at gmail.com)
Date: Sat Jul 3 19:48:17 EDT 2010

That is exactly what I knew I should be able to do, but didn't know
how to do. Thanks!

On Sat, Jul 3, 2010 at 7:27 PM, Anthony Cowley <acowley at seas.upenn.edu> wrote:
> On Sat, Jul 3, 2010 at 5:37 PM, Todd O'Bryan <toddobryan at gmail.com> wrote:
>> I'm sure the answer is in the docs somewhere, but I can't parse it out.
>>
>> I have a signature that provides a standard API and then a unit that
>> provides generic support for the API.
>>
>> Now I want to provide support for more specific implementations.
>> Conceptually, what I think I want to do is import the generic unit and
>> then redefine any functions whose behavior needs to change before I
>> export it. Is that possible?
>
> How about this,
>
> #lang racket
>
> (define-signature sig^ (foo bar))
>
> (define generic@
>  (unit
>   (import)
>   (export sig^)
>   (define foo "default")
>   (define bar "default")))
>
> (define specific@
>  (unit
>   (import)
>   (export sig^)
>   (define-values/invoke-unit generic@ (import) (export (except sig^ bar)))
>   (define bar 42)))
>
> (define-values/invoke-unit specific@ (import) (export sig^))
> (printf "foo = ~a, bar = ~a~n" foo bar)
>
> Anthony
>


Posted on the users mailing list.