Need help getting CLisp to read stdin into a list

I am working on converting some existing Python code to CLisp just like an exercise ...

The program reads a list of numbers and generates the mean, minimum, maximum, and standard deviation from the list. I am working on a file function:

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

      

It works when I call it

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

      

... but I want the program to read standard input, and I've tried different things with no luck.

Any advice?

+3


source to share


2 answers


Just individual problems:

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

      



Then you can use get-file

, as you have already done, and (get-stream *standard-input*)

.

+6


source


The variable is *standard-input*

bound to standard inputs:



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

      

+2


source







All Articles