定义一个函数,接受一个文件名并返回一个由字串组成的列表,来表示文件里的每一行
CL-USER> (defun pseudo-cat (file)
(with-open-file (str file :direction :input)
(let ((x nil))
(
do
((line (read-line str nil 'eof)
(read-line str nil 'eof)))
((eql line 'eof))
(push line x))x)))
STYLE-WARNING: redefining COMMON-LISP-USER::PSEUDO-CAT in DEFUN
PSEUDO-CAT
CL-USER> (pseudo-cat "COPYING")
("."
"Public License instead of this License. But first, please read"
"the library. If this is what you want to do, use the GNU Lesser General"
"may consider it more useful to permit linking proprietary applications with"
"into proprietary programs. If your program is a subroutine library, you"
" The GNU General Public License does not permit incorporating your program"
转化为表达式
CL-USER> (defun pseudo-cat (file)
(with-open-file (str file :direction :input)
(let ((x nil))
(
do
((line (read-line str nil 'eof)
(read-line str nil 'eof)))
((eql line 'eof))
(push (make-array 1 :initial-element line) x))
(reverse x))))
STYLE-WARNING: redefining COMMON-LISP-USER::PSEUDO-CAT in DEFUN
PSEUDO-CAT
CL-USER> (pseudo-cat "copying")
(#(" GNU GENERAL PUBLIC LICENSE")
#(" Version 3, 29 June 2007") #("")
#(" Copyright (C) 2007 Free Software Foundation, Inc. ")
#(" Everyone is permitted to copy and distribute verbatim copies")
#(" of this license document, but changing it is not allowed.") #("")
#(" Preamble") #("")
#(" The GNU General Public License is a free, copyleft license for")
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/133735/viewspace-741265/,如需转载,请注明出处,否则将追究法律责任。