小编Hop*_*all的帖子

随着打开文件读取额外的字符

我正在尝试将文件读入Common Lisp中的字符串(而不是列表中),但是我最终在字符串的末尾添加了额外的字符.仅当文件包含换行符或制表符等字符时才会发生这种情况; 空白似乎工作得很好.这是我的代码:

(defun load-file (filename)
  (with-open-file (stream filename 
                          :direction :input 
                          :if-does-not-exist :error)
    (let ((contents (make-string (file-length stream))))
      (read-sequence contents stream)
       contents)))
Run Code Online (Sandbox Code Playgroud)

请注意:遗憾的是,我不允许在此程序中同时使用循环或外部库.

lisp common-lisp

3
推荐指数
1
解决办法
400
查看次数

标签 统计

common-lisp ×1

lisp ×1