我正在努力将一些现有的 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/