[plt-scheme] Faking modules with define-values

From: Jon Rafkind (workmin at ccs.neu.edu)
Date: Sun Jun 25 13:47:34 EDT 2006

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))

I cant use a module since everything is already in a module. Since
nested modules arent allowed, I dont want to split everything up into
seperate files, and a `require' expects a file to contain one top level
module I figured I could emulate the same behavior with normal scoping
rules.

I guess I would have to use let* or something like that unless there is
some other way?


Posted on the users mailing list.