博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
lisp 习题 用列表元素标识文件一行。
阅读量:2496 次
发布时间:2019-05-11

本文共 1558 字,大约阅读时间需要 5 分钟。

定义一个函数,接受一个文件名并返回一个由字串组成的列表,来表示文件里的每一行
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/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/133735/viewspace-741265/

你可能感兴趣的文章
通向财务自由之路01_导读
查看>>
通向财务自由之路02_成功的决定因素:你
查看>>
中低频量化交易策略研发01_引言
查看>>
中低频量化交易策略研发06_推进的择时策略
查看>>
史丹·温斯坦称傲牛熊市的秘密
查看>>
期货市场技术分析01_理论基础
查看>>
期货市场技术分析02_趋势的基本概念
查看>>
期货市场技术分析03_主要反转形态
查看>>
期货市场技术分析04_持续形态
查看>>
期货市场技术分析05_交易量和持仓兴趣
查看>>
TB交易开拓者入门教程
查看>>
TB创建公式应用dll失败 请检查用户权限,终极解决方案
查看>>
python绘制k线图(蜡烛图)报错 No module named 'matplotlib.finance
查看>>
talib均线大全
查看>>
期货市场技术分析06_长期图表和商品指数
查看>>
期货市场技术分析07_摆动指数和相反意见理论
查看>>
满屏的指标?删了吧,手把手教你裸 K 交易!
查看>>
不吹不黑 | 聊聊为什么要用99%精度的数据回测
查看>>
高频交易的几种策略
查看>>
量化策略回测TRIXKDJ
查看>>