我正在尝试将文件读入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)
请注意:遗憾的是,我不允许在此程序中同时使用循环或外部库.