Re: How to avoid new line from stream
Jean Louis <[email protected]> Fri, 3 Aug 2018 11:36:03 +0200
| Newsgroups | gmane.lisp.clisp.general |
|---|---|
| Message-ID | <[email protected]> |
On Fri, Aug 03, 2018 at 05:40:40AM +0200, Max Zettlmeißl wrote: > On Fri, Aug 3, 2018 at 4:25 AM, Jean Louis <[email protected]> wrote: > > I am trying to solve the problem here that if > > there is no ending newline, my function is still > > printing it. > > > > (setf result (format nil "~{~A~%~}" (loop for line = (read-line in nil) > > while line > > collect line))) > > > > while I would need "something" as result. Somebody knows solution? > > > > What is happening here is no surprise. > Your format control string contains directions to append a line ending > after every element in your list. ("~%") > If you change it into "~{~A~}" you get your desired behaviour. > > There are many other things about your function which are rather > unclean: a starting point would be to use with-open-stream and > with-input-from-stream. Thank you. I found one reference here: https://rosettacode.org/wiki/Read_a_file_character_by_character/UTF8#Common_Lisp Right now it is working this way. (defun slurp-stream-io-command2 (command string) "Returns the output of a command to which string has been fed, very usable for markdown, emacs Org mode processing and similar" (let* ((stream (make-pipe-io-stream command :external-format "utf-8")) (in (two-way-stream-input-stream stream)) (out (two-way-stream-output-stream stream)) (result "")) (princ string out) (finish-output out) (close out) (setf result (with-output-to-string (var) (loop for c = (read-char in nil) while c do (format var "~a" c)))) (finish-output in) (close in) (close stream) result)) ------------------------------------------------------------------------------ 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