[plt-scheme] conditional module inclusion and compilation

From: Lee Spector (lspector at hampshire.edu)
Date: Wed Sep 2 17:34:28 EDT 2009

I've developed some code in DrScheme under Mac OS X that I also want  
to run sometimes under Linux -- it's computationally intensive stuff  
and I'll want to do development runs on my mac but then do lots of  
bigger runs on our Linux cluster.

I have some graphics in the Mac OS X version that I don't know how to  
produce in my command-line/text-based Linux environment, but I don't  
need the graphics there anyway. The graphics are just plots of  
progress which are useful when I'm developing and watching a run, but  
the cluster runs produce text files of data which are good enough. So  
to get the code working on the cluster I just removed "(require plot)"  
and all of the code that called anything from the plot module.

That worked but I don't want to have to do this kind of surgery on the  
code every time I move it to the cluster, which I'll be doing  
frequently. Ideally I'd like to be able to write my code in such a way  
that it knows where it's running and it includes the plot module and  
calls the plot code only if it's running somewhere appropriate. I do  
this in Common Lisp by using the #+: and #-: conditional compilation  
syntax and/or by looking for things in the variable *features*, which  
includes symbols that describe the environment. Is there anything  
similar in PLT?

I wouldn't mind having to manually change a flag to indicate the  
environment, e.g. to change the value in something like:

(define include-plots-in-reports #t)

But this doesn't actually help for two reasons:

- PLT won't let me wrap a call to "require" in a conditional  
expression -- it complains that it's not at the top level.
- If I comment out the "require" PLT still won't compile a file  
containing calls to functions in the missing module, even if those  
calls are never executed.

So whether my code knows where it's running or whether I have to tell  
it manually, I don't have a way of moving it to the Linux environment  
without manually editing out the "require" and all of the code that  
refers to the plot module.

Is there a good way to deal with this kind of thing in PLT that I'm  



Lee Spector, Professor of Computer Science
School of Cognitive Science, Hampshire College
893 West Street, Amherst, MA 01002-3359
lspector at hampshire.edu, http://hampshire.edu/lspector/
Phone: 413-559-5352, Fax: 413-559-5438

Check out Genetic Programming and Evolvable Machines:
http://www.springer.com/10710 - http://gpemjournal.blogspot.com/

Posted on the users mailing list.