Subject: Re: (Q) run batch job on scm???
From: rpw3@rigden.engr.sgi.com (Rob Warnock)
Date: 1997/09/02
Newsgroups: comp.lang.scheme
Message-ID: <5ufpqg$va9a@fido.asd.sgi.com>

Tony  Z. <zz@fleet.cc.purdue.edu> wrote:
+---------------
| I was wonder if there would a way to run batch jobs
| in "scm" implementation of Scheme. For example, I
| have the following set of stuff in a file:
| ===========
| (transcript-on "result.out")
| (load "sort.scm")
| (sort (1 3 7 9 4 6 5 2 8))
| (transcript-off)
| (quit)
| ===========
| I tried to run the job non-interactively, but no output was found
| in the file "result.out".
+---------------

[Note: To avoid an error, you'll need to quote that constant list...]

Transcript files contain *only* what was typed/displayed to/from the
top-level read-eval-print loop.  When you run a file non-interactively
(presumably by specifying "-f file" on the SCM command line), it's exactly
the same as executing (load "file"). And the value of each expression
evaluated during a "load" is not printed. [The top-level REPL isn't
doing anything, so nothing ends up in the transcript.] You'll need to
make the following changes:

1. Print (that is, "display" or "write") the values of any expressions
   you want to see, e.g.:

	(load "sort.scm")
	(display (sort '(1 3 7 9 4 6 5 2 8)))
	(newline)

2. Wrap the parts of your program containing any output in a re-direction:

	(load "sort.scm")
	(with-output-to-file
	  "result.out"
	  (lambda ()
	    (display (sort '(1 3 7 9 4 6 5 2 8)))
	    (newline)))

Alternatively, you can explicitly open an output file and change *every*
display, write, and newline in your program to specify the [optional]
second argument, in this case the port of the opened file, but that's
a lot more trouble, at least for a simple hack developed interactively
that you now want to run in "batch" mode.


-Rob

p.s. Of course, more complex programs -- and especially libraries intended
to be re-used -- should be developed from the *beginning* with all I/O calls
containing explicit port specifiers, which can be set to the value returned
by "(current-output-port)" during interactive development...

p.p.s. With SCM, you don't need an explicit "(quit)" in this situation.

-----
Rob Warnock, 7L-551		rpw3@sgi.com   http://reality.sgi.com/rpw3/
Silicon Graphics, Inc.		Phone: 650-933-1673 [New area code!]
2011 N. Shoreline Blvd.		FAX: 650-933-4392
Mountain View, CA  94043	PP-ASEL-IA