木纹标识lisp_lisp 习题 用列表元素标识文件一行。

定义一个函数,接受一个文件名并返回一个由字串组成的列表,来表示文件里的每一行

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/,如需转载,请注明出处,否则将追究法律责任。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值