0

我正在尝试将一些参数传递给一个将列添加到平面文件的新函数。电话是这样的:

(add-col-to-ff '(:absolute "home" "lambda" "Documents") "test-col-col"
               '(:absolute "home" "lambda" "Documents") "test-col-ff"     
               '(:absolute "home" "lambda" "Documents") "test-col-new.txt") 

但是 SLIME 返回错误:

#<SB-SYS:FD-STREAM for "file /home/lambda/Documents/test-col-new.txt" 
{B50D7E1}> is not a character input stream.
[Condition of type SIMPLE-TYPE-ERROR]
Backtrace:
  0: (SB-KERNEL:ILL-IN #<SB-SYS:FD-STREAM for "file /home/lambda/Documents/test-    
     col-new.txt" {B50D7E1}>)

我想知道,我在这里错过了什么?流布局似乎很好:

(defun add-col-to-ff (col-dir col-file 
                      ff-dir ff-file 
                      out-dir out-file)
  (let ((M (make-ff-array ff-dir ff-file))
        (vec (vec-from-1col-ff col-dir col-file))
        (path (make-pathname :name out-file 
                             :directory out-dir)))
    (with-open-file (addcol-str path :direction :output)
      (do ((line (read-line addcol-str nil 'eof)
                 (read-line addcol-str nil 'eof))
           (i 0 (1+ i)))
          ((eql i (array-dimension M 1))) 
          (dotimes (k (array-dimension M 0))
            (cond ((eql (1+ k) (array-dimension M 0))
                   (format addcol-str "~A ~A~%" (aref M i k) (svref vec k)))
                  ((and (eql (1+ i) (array-dimension M 1)) 
                        (eql (1+ k) (array-dimension M 0)))
                   (format addcol-str "~A ~A"  (aref M i k) (svref vec k)))
                  (t (format addcol-str "~A " (aref M i k)))))))))                 
4

2 回答 2

2

你打开一个输出流。但随后您尝试使用READ-LINE. 这自然是行不通的。

于 2013-02-19T16:25:57.707 回答
0

按照接受的答案,我将do宏替换dotimes为如下:

(defun add-col-to-ff (col-dir col-file 
                      ff-dir ff-file 
                      out-dir out-file)
  (let ((M (make-ff-array ff-dir ff-file))
        (vec (vec-from-1col-ff col-dir col-file))
        (path (make-pathname :name out-file 
                             :directory out-dir)))
    (with-open-file (addcol-str path :direction :output)
      (dotimes (i (array-dimension M 0)) 
          (dotimes (k (array-dimension M 1))
            (cond ((eql (1+ k) (array-dimension M 0))
                   (format addcol-str "~A ~A~%" (aref M i k) (svref vec k)))
                  ((and (eql (1+ i) (array-dimension M 0)) 
                        (eql (1+ k) (array-dimension M 1)))
                   (format addcol-str "~A ~A"  (aref M i k) (svref vec k)))
                  (t (format addcol-str "~A " (aref M i k))))))))) 

奇迹般有效。

于 2013-02-19T16:52:40.610 回答