Re: Reading pipe from *standard-input*?
Jean Louis <[email protected]> Thu, 23 Mar 2017 18:24:07 +0300
| Newsgroups | gmane.lisp.clisp.general |
|---|---|
| Message-ID | <[email protected]> |
On Thu, Mar 23, 2017 at 10:59:10AM -0400, Sam Steingold wrote:
> > (defun main nil
>
> It is extremely unidiomatic to use "nil" for arglist.
> `(defun main () ...)` looks much better.
It says in documentation that empty list and nil is same thing. Anyway
it works. You have different experience, and you get surprised what
people write there for a code, who are mostly separate from other
world, like me now in Uganda.
> > (let ((input (with-open-stream (str *standard-input*)
> > (alexandria.0.dev:read-stream-content-into-string str))))
>
> why not just read from *standard-input* ?
You are right, I don't need alexandria for that. I changed it to, but
I guess it is not 100% correct, due to reading the lines from stream
and formatting with new line, as how do I know if there is new line on
the end.
(defparameter memdir "/run/shm/")
(defparameter tmp-file "rcd-wrs-XXXXXX")
(defparameter tmp-org (format nil "~a~a.org" memdir tmp-file))
(defparameter tmp-md (format nil "~a~a.md" memdir tmp-file))
(defun main nil
(let ((input (with-open-stream (str *standard-input*)
(loop :for line = (read-line *standard-input* nil nil)
:while line
:do (format t "~A~%" line))))) ;;; I guess this
;; one here is not correct
(with-open-file (stream tmp-org :if-exists :supersede :if-does-not-exist :create :external-format "utf-8")
(format stream input))
(shell (format nil "emacs -Q -l ~~/.emacs.d/elpa/org-20170210/org-autoloads.el \"~a\" --batch -f org-mode -f org-md-export-to-markdown --kill" tmp-org))
(format t (with-open-file (stream tmp-md :direction :input)
(loop :for line = (read-line *standard-input* nil nil)
:while line
:do (format t "~A~%" line))))
(exit)))
(main)
> it's a very bad idea to pass a string to format as the format string.
> you will get an error if your (alexandria...) returns a string
> containing "~".
Yes, I see, I had this error once back.
Thank you.
Jean
------------------------------------------------------------------------------
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