Re: Reading pipe from *standard-input*?
Sam Steingold <[email protected]> Mon, 27 Mar 2017 08:33:54 -0400
| Newsgroups | gmane.lisp.clisp.general |
|---|---|
| Message-ID | <[email protected]> |
> * Jean Louis <[email protected]> [2017-03-24 00:00:23 +0300]: > > Also I am sure there is more elegant reading from *standard-input* and > writing to *standard-output* then this kind of list making and > converting to string. If somebody knows, let me know. this is a common idiom: (let ((input (loop for line = (read-line in nil nil) while line collect line))) ...) > (setf input (format nil "~{~a~^~%~}" (reverse input))) > (with-open-file (stream tmp-org :direction :output :if-exists :supersede :if-does-not-exist :create :external-format "utf-8") > (princ input stream)) this is a very poor idiom. not only your last line is not NL-terminated, but you are creating the full input string in memory. this is the more common approach: (with-open-file (out tmp-org :direction :output external-format "utf-8") (dolist (line input) (write-line line out))) -- Sam Steingold (http://sds.podval.org/) on darwin Ns 10.3.1504 http://steingoldpsychology.com http://www.childpsy.net http://mideasttruth.com https://ffii.org http://thereligionofpeace.com http://iris.org.il A number problem "solved" with floats turns into 1.9999999999999998 problems. ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot _______________________________________________ clisp-list mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/clisp-list