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

标签 python lisp common-lisp clisp

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

相关文章:

php - 图像大小调整 Web 服务

python - Scapy 中的 HTTP GET 数据包嗅探器

python - mount 返回非零退出代码 64

lisp - emacs lisp 无法启动

stream - CCL Lisp 中的破管错误

common-lisp - 错误 : can't read server: no such variable when using ltk remotely

python - 如何将输入从条目添加到Python中的标签?

functional-programming - 以下函数式编程模式的正确术语是什么?

common-lisp - 用(格式)重复字符串/字符

common-lisp - 从循环列表中删除自引用