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

Need help getting CLisp to read standard input into a list

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

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

有什么建议吗?

变量*standard-input*绑定到标准输入:

(defun get-from-standard-input ()
   (loop for line = (read-line *standard-input* nil)
         while line
         collect (parse-float line)))

只是分开关注点:

(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*)