home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 9 / 09.iso / e / e032 / 3.ddi / FILES / PROGRAMM.PAK / TRANSCRI.M < prev    next >
Encoding:
Text File  |  1992-07-29  |  1.3 KB  |  52 lines

  1.  
  2. (*********************************************************************
  3.  
  4.         Adapted from
  5.         Roman E. Maeder: Programming in Mathematica,
  6.         Second Edition, Addison-Wesley, 1991.
  7.  
  8.  *********************************************************************)
  9.  
  10.  
  11. Transcript::usage = "Transcript[filename] opens filename for a transcript
  12.     of the current session. It clobbers $Post"
  13. EndTranscript::usage = "EndTranscript[] closes the transcript opened with Transcript[]."
  14.  
  15. Begin["`Private`"]
  16.  
  17. `transcript=""
  18.  
  19. Transcript[filename_] := (
  20.     transcript = OpenWrite[filename];
  21.     If[ transcript === $Failed, Return[transcript] ];
  22.     $Post := ($Post := MakeTranscript; Identity);
  23.     transcript
  24.     )
  25.  
  26. EndTranscript[] := (
  27.     MakeTranscript;
  28.     $Post =. ;
  29.     Close[transcript]
  30.     )
  31.  
  32. GetInputForm[lhs_ :> rhs_] :=
  33.     Module[{input},
  34.         input = HoldForm[rhs];
  35.         input = Characters[ToString[InputForm[input]]];
  36.         input = Drop[input, {1, 9}]; (* HoldForm[ *)
  37.         input = Drop[input, -1];     (* ]         *)
  38.         StringJoin @@ input
  39.     ]
  40.     
  41. MakeTranscript :=
  42.     Module[{input, output},
  43.         input  = GetInputForm[ DownValues[In][[-2]] ];
  44.         output = GetInputForm[ DownValues[Out][[-1]] ];
  45.         WriteString[transcript, "(* In[", $Line-1, "]=\n", input, "\n*)\n"];
  46.         WriteString[transcript, "\n", output, "\n\n"];
  47.         Identity
  48.     ]
  49.  
  50. End[]
  51. Null
  52.