Re: How to solve: module 'syscalls' requires package OS
<[email protected]> Fri, 24 Mar 2017 13:51:21 +0000
| Newsgroups | gmane.lisp.clisp.general |
|---|---|
| Message-ID | <a39a60a3ea2b48f6b0d8567ced6e8cef@HE104834.emea1.cds.t-internal.com> |
Jean Louis asked:
>module 'syscalls' requires package OS
>How do I solve that?
Do not require syscalls. :-)
The code you provided only uses standard Common Lisp and a few CLISP extensions (ext:saveinitmem, ext:shell).
> (let ((input (with-open-stream (str *standard-input*)
Do you realize that WITH-OPEN-STREAM closes the stream upon exit?
Unless you really know what you do, programs are usually advised against closing their stdio handles.
>(defparameter memdir "/run/shm/")
Don't reinvent the wheel. There's a reason people have, for decades, recommended adding namespace decorations to special variables, e.g. use *memdir*.
> (format stream input))
That is as bad as printf(stream, format) in C. This will error out if there happens to be
any #\~ resp. '%' in the input!
In C code, that might be your open door to a security vulnerability.
There's a life beside FORMAT, half a dozen functions in CL begin with PRIN, e.g. PRINC.
(let ((input (with-open-stream (str *standard-input*)
(loop :for line = (read-line *standard-input* nil nil)
:while line
:do (format t "~A~%" line)))))
(with-open-file (stream tmp-org :if-exists :supersede :if-does-not-exist :create :external-format "utf-8")
(format stream input))
Huh? Why store a whole intermediate copy in RAM?
Why not immediately copy *standard-input* to a file-stream?
Think pipes & parallelism & composition, not sequential step after step processing.
> (let ((input (with-open-stream (str *standard-input*)
> (loop :for line = (read-line *standard-input* nil nil)
So you create a stream handle but nevertheless call read-line on another stream?
I believe I can guess what you want to achieve, however the above logic is broken. Think about what WITH-OPEN-STREAM returns as values. Think about what values LOOP returns.
Do you want to operate on streams or strings? Do you aim for a functional programming or an imperative programming style?
Regards,
Jörg Höhle
------------------------------------------------------------------------------
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