File input/output is part of Short Circuit's Console Program Basics selection.
Task

Create a file called   "output.txt",   and place in it the contents of the file   "input.txt",   via an intermediate variable.

In other words, your program will demonstrate:

   how to read from a file into a variable
   how to write a variable's contents into a file


Oneliners that skip the intermediate variable are of secondary interest — operating systems have copy commands for that.




:set-state-ok t
 
(defun read-channel (channel limit state)
   (mv-let (ch state)
           (read-char$ channel state)
      (if (or (null ch)
              (zp limit))
          (let ((state (close-input-channel channel state)))
             (mv nil state))
          (mv-let (so-far state)
                  (read-channel channel (1- limit) state)
             (mv (cons ch so-far) state)))))
 
(defun read-from-file (filename limit state)
   (mv-let (channel state)
           (open-input-channel filename :character state)
      (mv-let (contents state)
              (read-channel channel limit state)
         (mv (coerce contents 'string) state))))
 
(defun write-channel (channel cs state)
   (if (endp cs)
       (close-output-channel channel state)
       (let ((state (write-byte$ (char-code (first cs))
                                 channel state)))
          (let ((state (write-channel channel
                                      (rest cs)
                                      state)))
              state))))
 
(defun write-to-file (filename str state)
   (mv-let (channel state)
           (open-output-channel filename :byte state)
      (write-channel channel (coerce str 'list) state)))
 
(defun copy-file (in out state)
   (mv-let (contents state)
           (read-from-file in (expt 2 40) state)
      (write-to-file out contents state)))