Subject: Re: scheme scripting
From: rpw3@rigden.engr.sgi.com (Rob Warnock)
Date: 2000/07/10
Newsgroups: comp.lang.scheme
Message-ID: <8kc3si$3kdn8$1@fido.engr.sgi.com>
Michael Vanier  <mvanier@endor.bbb.caltech.edu> wrote:
+---------------
| rpw3@rigden.engr.sgi.com (Rob Warnock) writes:
| > 	% cat foo
| > 	#!/usr/local/bin/mzscheme -r
| > 	(write argv)
| > 	(newline)
| > 	% foo bar baz gorp
| > 	#3("bar" "baz" "gorp")
| > 	% 
| 
| BTW your script doesn't work on my machine, because "mzscheme" is a shell
| script.
+---------------

Well, yes, as installed by default. I think they do their script thing
to make it possible to NFS-mount the binaries from different machine
architectures. There's some discussion of this in the top-level README
file in the PLT distribution:

	The files in plt/bin are shell scripts. The actual executable
	binaries for mred and mzscheme are in plt/.bin in a platform-dependent
	subdirectory. (If you have downloaded the source code distribution,
	the binaries will be absent and must be compiled.) The sh scripts pick
	an appropiate binary based on `uname`, so a single plt directory can
	be used in a multi-platform environment. This causes problems for
	writing MzScheme scripts; see
		 plt/collects/doc/help/scheme/misc/script.html
	for a way around the problem.

That script doc is also at <URL:http://www.cs.rice.edu/CS/PLT/packages/
doc/help/scheme/misc/script.html>. There they suggest a #!/bin/sh trampoline
such as this:

	#!/bin/sh
	string=? ; exec ${PLTHOME}/bin/mzscheme -r $0 $0 ${1+"$@"}
	...
	 ...scheme code...
	  ...

+---------------
| If the path points to the mzscheme binary then it works.
+---------------

Yeah, I find the trampoline hack to be slightly ugly, not to mention a little
bit slower on startup. (Not much slower, but when doing cgi-bin scripting,
why add that extra overhead?) So I prefer to make /usr/local/bin/mzscheme
point directly to the architecture-specific binary.

+---------------
| I've been trying to figure this out for days, and I can find no mention
| of the #! support in the mzscheme documentation, so... thanks!
+---------------

Well, "PLT MzScheme: Language Manual/Support Facilities/Input Parsing"
<URL:http://www.cs.rice.edu/CS/PLT/packages/doc/mzscheme/node151.htm>
(at the very bottom) has this to say, so it *is* documented:

	If the first line of a loaded file begins with #!, it is ignored
	by the default load handler. If an ignored line ends with a
	backslash (``\''), then the next line is also ignored. 


-Rob

-----
Rob Warnock, 41L-955		rpw3@sgi.com
Applied Networking		http://reality.sgi.com/rpw3/
Silicon Graphics, Inc.		Phone: 650-933-1673
1600 Amphitheatre Pkwy.		PP-ASEL-IA
Mountain View, CA  94043