gpt4 book ai didi

python - 需要帮助让 CLisp 将标准输入读入列表

转载 作者:太空宇宙 更新时间:2023-11-03 12:58:46 25 4
gpt4 key购买 nike

我正在努力将一些现有的 Python 代码转换为 CLisp,作为练习 ...

程序读取数字列表并根据列表创建平均值、最小值、最大值和标准差。我有基于文件的功能工作:

(defun get-file (filename)
(with-open-file (stream filename)
(loop for line = (read-line stream nil)
while line
collect (parse-float line))))

当我称它为

(get-file "/tmp/my.filename")

...但我想让程序读取标准输入,我试过了各种运气不好的事情。

有什么建议吗?

最佳答案

只是分离关注点:

(defun get-stream (stream)
(loop for line = (read-line stream nil)
while line
collect (parse-float line)))

(defun get-file (filename)
(with-open-file (stream filename)
(get-stream stream)))

然后您可以像以前一样使用 get-file(get-stream *standard-input*)

关于python - 需要帮助让 CLisp 将标准输入读入列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30117226/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com