Subject: Re: I'm not a comp scientist
From: rpw3@rigden.engr.sgi.com (Rob Warnock)
Date: 22 Aug 2001 12:11:37 GMT
Newsgroups: comp.lang.scheme
Message-ID: <9m07hp$d96lr$1@fido.engr.sgi.com>
Barry Margolin  <barmar@genuity.net> wrote:
+---------------
| IMHO, Lisp/Scheme program files should not contain anything but
| definitions; you shouldn't even have that call to the main procedure
| at the end of the file.  The way to start a Scheme program should be:
| 
| (load "filename")
| (main-function)
| 
| The reason for this is that sometimes you may want to load the file
| definitions without starting the program.  For instance, when you're
| debugging you may want to run one of the internal functions rather than
| the main function.
+---------------

Well, I mildly disagree, since your approach requires a *minimum* of
two files for even a simple script, something that makes Scheme look
hard to use when compared to, say, the way people write Perl scripts.
Instead of saying to someone, "Oh, here, copy this script", you have
to say "Copy these two scripts, and adjust the path in the ``load''
in first one to point to where you put the second one". (*Ugh!*)

But I definitely do agree with the need for a choice of whether to
load-and-run or just load for debugging. The idiom I tend to use in
my MzScheme scripts goes something like this:

	#!/usr/local/bin/mzscheme -r

	(define (main parsed-args)
	  ...)

	...other definitions and *constant* initializations...

	(if (getenv "MZ_DEBUG")
	  (read-eval-print-loop)
	  (main (getopt argv)))

With $MZ_DEBUG not defined, the program runs & exits. With it defined,
all the definitions/initializations get done, then a REPL gets fired up,
from which you can still call "main" if you want. Even more than once,
if you like.

By the way, I also do the same thing when writing CGI scripts, but
the test at the end is slightly different:

	(if (getenv "REQUEST_METHOD")	; called from a web server?
	  (main)			; yup, go!
	  (read-eval-print-loop))	; nope, debugging.


-Rob

-----
Rob Warnock, 30-3-510		<rpw3@sgi.com>
SGI Network Engineering		<http://reality.sgi.com/rpw3/>
1600 Amphitheatre Pkwy.		Phone: 650-933-1673
Mountain View, CA  94043	PP-ASEL-IA

[Note: aaanalyst@sgi.com and zedwatch@sgi.com aren't for humans ]