首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >LISP文件读取循环存储和序列号

LISP文件读取循环存储和序列号
EN

Stack Overflow用户
提问于 2017-06-06 04:19:40
回答 1查看 211关注 0票数 0

你好,我有关于文件读取中的LISP循环条件和循环中的序列号的问题。

我想要做的是读取一个文件并保存数据(我只是实现了它)。

但是要执行这个迭代,我不知道如何完成循环。

我只想在文件结束时完成循环。

我希望在循环中使用序列号。

例如,我想将数据保存在struct s1、s2、s3、s4中……每次循环循环,但如何做到这一点?

它简单地用C语言伪代码表示这一点。

代码语言:javascript
复制
int i=0;
while( != EOF){

    read file in line
    save data into struct[i]
    i++
}

我的密码是

代码语言:javascript
复制
(loop 
    ??(setf p(n) (make-player
        :name (read-line *file nil)
        :team (read-line *file nil)
        :game-number (read-line *file nil)
    )
    ??(setf (gethash (player-name p(n) Player_DB) p(n))

    ??(when ( = (read-line *file) " ") (return 0))  
)   

)

EN

Stack Overflow用户

回答已采纳

发布于 2017-06-06 07:31:42

你有两个选择:

使用读行,它返回零,因此您可以停止使用该值,或者在行为零时指定一个值来停止它。

例如:

  • 停止使用自定义符号 (使用-打开文件( "/Users/toni/learn/lisp/cl-l/stackoverflow/scripts/list-file.txt")流( line =(读行流nil 'foo)的循环),直到(eq line 'foo) do (打印行) 结果: “-rw-r-r-1 toni staff 22 18 abr 09:34 calimero_1.txt”-rw-r-r-1 toni staff 1 18 abr 09:34 calimero_2.txt“-rw-r-r-1 toni staff 0 18 abr 09:34 calimero_3.txt”-rw-r-1 toni staff 149 abr 09:34 calimero_2.txt“-rw-r-1 toni staff 0 abr 09:34 calimero_3.txt”-rw-r-r-1 toni staff 149 abr 09:34 charpos.lisp“-rw-r-r-1 toni staff 0 abr 09:34 calimero_3.txt”R-1 toni staff 485 3 5月16日:14 distributive-lists.org“-rw- r-- r-1 toni staff 1237 18 abr 09:34 do-mac.lisp”-rw-r-1 toni staff 120 / 09:34下载-all-pdfs.lisp“-rw-1 toni staff 3111 18 abr 09:34 emacs-rest客户机”-rw-r-1 toni工作人员1111 30 5月15:46等功能-在-公共-lisp.org“-rw-r-r-1 toni员工12 18 abr 09:34 filename.txt”-rw-r-r-1 toni staff 757 18 abr 09:34 -查找所有对象-in-apackage.lisp“-rw-r-r-1 toni staff 355 2009年4月18 :34 flatten-one.find”-rw-r-rw-r-1 toni staff 813 18 abr 09:34 instrospection.lisp-Money.lisp“-rw-r-r-1 toni staff 2137 18 abr 09:34散列表-eficiency.lisp”-rw-r-r-1 toni staff 4230 04月09:34 instrospection.lisp“-rw-r-1 toni staff 919 2009年4月18日:34 mapcar_and_lambda.lisp”-rw-r-1 toni员工11713 09年4月18 :34 mastermind.lisp“-rw-r-r-1 toni staff 368 a abr 09:34 method-missing.lisp”-rw-r-1 toni staff 614 18 abr 09:34 method_missing.rb“-rw-r-r-1 toni staff 2 18 abr 09:34 patofante_1.txt”-rw-r-1 toni staff 314 profiling.org 18“-rw-r-1 toni staff 1265 18 / 09:34递归-多一功能.size”-rw-r-r-1 toni staff 1154 18 abr 09:34 size-explosing file.lisp“-rw-r-r-1 toni staff 592 18 / 09:34排序-协调”-rw-r-r-1 toni staff -mongo.lisp“09:34 stackoverflow mongo.lisp”“-rw-r1 toni staff 61194 18 abr 09:34 train.csv“-rw-r-r-1 toni staff 218 26 abr 17:17 :17变量-rw-r-r-1 toni staff 1792 18 abr 09:34个向量-vs-lisp.lisp”-rw-r-1 toni staff 190 /09年4月18日:34个奇怪的编解码器-rw-r-r-1 toni staff 629 18 abr 09:34写-a-list.lisp“
  • 停止与零 (使用-打开文件( "/Users/toni/learn/lisp/cl-l/stackoverflow/scripts/list-file.txt")流(行的循环=(读行流为零),直到(空行) do (打印行) 结果: “-rw-r-r-1 toni staff 22 18 abr 09:34 calimero_1.txt”-rw-r-r-1 toni staff 1 18 abr 09:34 calimero_2.txt“-rw-r-r-1 toni staff 0 18 abr 09:34 calimero_3.txt”-rw-r-1 toni staff 149 abr 09:34 calimero_2.txt“-rw-r-1 toni staff 0 abr 09:34 calimero_3.txt”-rw-r-r-1 toni staff 149 abr 09:34 charpos.lisp“-rw-r-r-1 toni staff 0 abr 09:34 calimero_3.txt”R-1 toni staff 485 3 5月16日:14 distributive-lists.org“-rw- r-- r-1 toni staff 1237 18 abr 09:34 do-mac.lisp”-rw-r-1 toni staff 120 / 09:34下载-all-pdfs.lisp“-rw-1 toni staff 3111 18 abr 09:34 emacs-rest客户机”-rw-r-1 toni工作人员1111 30 5月15:46等功能-在-公共-lisp.org“-rw-r-r-1 toni员工12 18 abr 09:34 filename.txt”-rw-r-r-1 toni staff 757 18 abr 09:34 -查找所有对象-in-apackage.lisp“-rw-r-r-1 toni staff 355 2009年4月18 :34 flatten-one.find”-rw-r-rw-r-1 toni staff 813 18 abr 09:34 instrospection.lisp-Money.lisp“-rw-r-r-1 toni staff 2137 18 abr 09:34散列表-eficiency.lisp”-rw-r-r-1 toni staff 4230 04月09:34 instrospection.lisp“-rw-r-1 toni staff 919 2009年4月18日:34 mapcar_and_lambda.lisp”-rw-r-1 toni员工11713 09年4月18 :34 mastermind.lisp“-rw-r-r-1 toni staff 368 a abr 09:34 method-missing.lisp”-rw-r-1 toni staff 614 18 abr 09:34 method_missing.rb“-rw-r-r-1 toni staff 2 18 abr 09:34 patofante_1.txt”-rw-r-1 toni staff 314 profiling.org 18“-rw-r-1 toni staff 1265 18 / 09:34递归-多一功能.size”-rw-r-r-1 toni staff 1154 18 abr 09:34 size-explosing file.lisp“-rw-r-r-1 toni staff 592 18 / 09:34排序-协调”-rw-r-r-1 toni staff -mongo.lisp“09:34 stackoverflow mongo.lisp”“-rw-r1 toni staff 61194 18 abr 09:34 train.csv“-rw-r-r-1 toni staff 218 26 abr 17:17 :17变量-rw-r-r-1 toni staff 1792 18 abr 09:34个向量-vs-lisp.lisp”-rw-r-1 toni staff 190 /09年4月18日:34个奇怪的编解码器-rw-r-r-1 toni staff 629 18 abr 09:34写-a-list.lisp“
票数 2
EN
查看全部 1 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44381346

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档