[plt-scheme] Faking modules with define-values

From: Eli Barzilay (eli at barzilay.org)
Date: Sun Jun 25 14:20:06 EDT 2006

On Jun 25, Jon Rafkind wrote:
> I would like to provide some functions to the top-level but allow those
> functions to have access to a separate scope in which they are defined.
> Basically a pseudo-module system. I thought I could achieve this with
> define-values but define-values only allows one expression and no inner
> defines, so I cant use things like define-struct. Something like this:
> 
> (define-values (make-foo foo-f)
>    (define BLAH 2)
>    (define-struct foo (f))
>    (define (my-make-foo x)
>       (make-foo (+ BLAH x)))
>   (values my-make-foo foo-f))

Try this:

(define-values (make-foo foo-f)
  (let ()
    (define BLAH 2)
    (define-struct foo (f))
    (define (my-make-foo x)
      (make-foo (+ BLAH x)))
    (values my-make-foo foo-f)))

-- 
          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
                  http://www.barzilay.org/                 Maze is Life!


Posted on the users mailing list.