[plt-scheme] require with custom modules

From: Jean-Pierre Lozi (jean-pierre at lozi.org)
Date: Sat Nov 10 15:00:40 EST 2007

On Nov 10, 2007 7:34 PM, Cyprien Nicolas <c.nicolas at gmail.com> wrote:
> Hi
>
> I'm building an application to compile a subset of BASIC expressions
> into scheme (my Interpretation course at the University of Nice), I
> have defined several modules to handle the compilation process (lexer,
> parser, etc).
>
> The application is launched by a main.scm file located in the root
> directory of the app.
> The GUI is located in a gui/ dir, and the modules in the parse/ dir
>
> So I use (load (build-path (current-directory) "gui" "gui.scm") to
> load the GUI, and I'd like to do the same for require my modules,
> because gui.scm needs to load some of them.
>
> I don't want to use the form (require (file "../parse/parser.ss"))
> because I hate using .. in file paths, and depending on where the
> require is made, every path will be different.
> So I think using (build-path ) could be a cleaner way, after defining
> every dir in the main.scm
> For example, the path to the lexer will be (build-path
> myapp-modules-directory "lexer.ss").

Oh and btw, if you want to specify paths in your require statement
instead of directly giving the path structure (which seems to be what
you want, as you speak of storing the paths), you would probably
prefer this macro :

(define-macro (my-require2 path)
   `(require ,(eval path)))

(my-require2 (build-path (current-directory) 'up "parse" "parser.ss"))

Hope this helps,

-- 
Jean-Pierre Lozi
http://www.lozi.org
mailto:jean-pierre at lozi.org


Posted on the users mailing list.