[racket] overriding unit functions with other units

From: Anthony Cowley (acowley at seas.upenn.edu)
Date: Sat Jul 3 19:27:54 EDT 2010

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.