Question...
How does one read standard input ie: my_script < file.in
So far I have:
Code: Select all
#!/usr/bin/env clisp
# chmod +x my_script
(loop for line = (read-line stream nil :eof)
until (eq line :eof)
print line ))
(bye)
Code: Select all
#!/usr/bin/env clisp
# chmod +x my_script
(loop for line = (read-line stream nil :eof)
until (eq line :eof)
print line ))
(bye)
The language is called Common Lisp, which is usually shortened to CL. CLISP is a name of a particular implementation of the ANSI CL standard.michael wrote:Hi folks, new to clisp (just started today in fact).
By reading from a stream bound to global variable *terminal-io*. But do note that this is not really how CL is commonly used. Particularly when starting you should primarily use the REPL. Read a book like Practical Common Lisp for an introduction.michael wrote:How does one read standard input ie: my_script < file.in
Code: Select all
#!/usr/bin/clisp
(loop for line = (read-line *terminal-io* nil :eof)
until (eq line :eof)
do (print line))
You bet - the more data I have, the more I learn. Is there a problem with that?vanekl wrote:asked and answered on c.l.l.
Thanks, I've just began reading Practical Lisp too. So, here we go!jstoddard wrote:I have to second that the REPL is invaluable; you're missing out on one of the most useful parts of Lisp programming. That said, if you were a conformist, you probably wouldn't be learning Lisp anyway.
I'm new as well; just a few days into Lisp, and just finished the "Practical Common Lisp" book, but here goes a shot:
read-line only needs the name of the stream (not the word "stream") to be happy. You need that nil before :eof to tell it not to give an error when it reaches the end of the file.Code: Select all
#!/usr/bin/clisp (loop for line = (read-line *terminal-io* nil :eof) until (eq line :eof) do (print line))
You were also missing a parenthesis on the left side of print line, and I believe the keyword "do" is appropriate there. This works for me; when I direct a file into it, it prints out that file's contents...