0

我正在创建一个将列添加到平面文件的函数。到目前为止,我有:

(defun ff-from-vector (vec dir file)
  (with-open-file (ff-vec-str (make-pathname   :name file
                                               :directory dir)
                                               :direction :output
                                               :if-exists :overwrite)
    (dotimes (i (length vec))
      (format ff-vec-str "~A~%" (svref vec i)))))


(defun vec-from-1col-ff (dir file)
  (let ((col (make-array `(,(ff-rows dir file))))) 
        (with-open-file (ff-col-str (make-pathname  :name file
                                                    :directory dir)
                                                    :direction :input)
      (do ((line (read-line ff-col-str nil 'eof) 
                 (read-line ff-col-str nil 'eof))  
           (i 0 (incf i)))
           ((eql line 'eof))
           (setf (aref col i) (read-from-string line))))
  col))


(defun add-col-to-ff (col-dir col-file ff-dir ff-file)
  (ff-from-vector (vec-from-1col-ff col-dir col-file)   
                  ff-dir 
                  ff-file))

但是,当我从文件中读取时:

2 
2
2
2 

并尝试覆盖文件:

1 1 1 1
1 1 1 1
1 1 1 1
1 1 1 1

我得到:

2 
2
2
2 
1 1 1 1
1 1 1 1
1 1 1 1
1 1 1 1

本质上我的问题是:什么函数或代码将格式移动到输出文件的行尾?这样我就可以得到:

1 1 1 1 2
1 1 1 1 2
1 1 1 1 2
1 1 1 1 2
4

1 回答 1

1

您不能简单地将更多输出添加到文件中的各个行而不覆盖某些数据。

创建一个新文件并将输出放在那里,从两个输入文件中获取数据。

于 2013-02-15T12:57:33.783 回答