Exercise 1.1 in the textbook asks you to find out how your implementation of Scheme can be made to record a session in a file.
SCM handles this by providing two procedures that can be invoked in
interactive mode. The transcript-on
procedure takes one
operand, a string that names the file in which the session is to be
recorded. The transcript-off
procedure takes no operands.
Everything that is read or written by SCM between the call to
transcript-on
and the call to transcript-off
is
stored in the specified file.
Here's a sample interaction that uses these procedures:
post% scm -p1 > (+ 2 3) 5 > (transcript-on "foo.log") #<unspecified> > (+ 4 5) 9 > (transcript-off) #<unspecified> > (+ 6 7) 13At this point, the file
foo.log
contains the following lines:
#<unspecified> > (+ 4 5) 9 > (transcript-off)The
#<unspecified>
at the beginning of
foo.log
is SCM's response to the call to
transcript-on
; since the response was printed after the
transcriber was turned on, it gets included in the transcript. At the end
of foo.log
, you see the reverse situation; the call to
transcript-off
was read before the transcriber was turned off,
so it gets included in the transcript, but the response was not printed
until afterwards, so it is not included.