Subject: [clisp-list] read-byte and *standard-input*

From: "Hoehle, Joerg-Cyril" <[email-masked]>
Date: Wed May 14 08:44:14 2003

Thibault Langlois wrote:
>$ clisp -norc -q -x "(progn (print (lisp-implementation-version)) (setf
>(stream-element-type *standard-input*) '(unsigned-byte 8)))"
>
>"2.30 (released 2002-09-15) (built 3261851213) (memory 3261852080)" 
>*** - (SETF STREAM-ELEMENT-TYPE) on #<INPUT STRING-INPUT-STREAM> is
>illegal

Note the STRING-INPUT-STREAM: CLISP has put your -x expression "(progn (print ...)" into a (make-string-input-stream "...") and is reading from that.
You're not yet talking to the real standard-input.

$ clisp -q -norc -x '*standard-input*'
#<INPUT STRING-INPUT-STREAM>

IIRC, it's only after all -x options will have been processed that *standard-input* will see the real thing.

$ clisp -q -norc -x '(read-char *standard-input*)'
#\Newline ; I didn't type anything. It's just there because of -x I believe.

>I must be doing something wrong.
Maybe, maybenot.

One thing I just saw in the source code is that if you use -x without the new -repl, then *standard-input* will only be bound to this string-input-stream. I.e., the tty/pipe *standard-input* is lost!

This enters a REPL
clisp
clisp -repl

This does not
clisp -x
clisp -c
clisp file

Not affecting REPL behaviour:
-i
-interactive-debug

Which means that
clisp -i foo.lisp -x '(main)'
cannot be used to read from standard input in x. Maybe this should be put into clisp.html or impnotes.

You need to save *standard-input* in foo.lisp and use that saved value in the -x expression.

clisp -x '...' foo.lisp
does not work as (naively?) expected, either.

$ clisp -q -x '123' /tmp/binary.lisp
*** - EVAL: variable 123/TMP/BINARY.LISP has no value

Oh well, it looks like it's time for a HOWTO (any volunteer?). Keys are (clisp --help)
Actions:
 -c [-l] lispfile [-o outputfile] - compile LISPFILE
 -x expressions - execute the expressions, then exit
 lispfile [argument ...] - load lispfile, then exit
I.e. you have to choose among these, and cannot combine.

Regards,
	Jorg Hohle.

---

From: Thibault Langlois <[email-masked]>
Date: Wed May 14 10:06:09 2003

> I.e. you have to choose among these, and cannot combine.

Thank you for your very clear explanations.
Here is an example that illustrates some of the subtle aspects I did not
know.

exotica$ cat /tmp/test.lisp

(defvar *the-real-input* *standard-input*)

(defun good ()
  (setf (stream-element-type *the-real-input*) '(unsigned-byte 8))
  (print
   (loop repeat 10
         collect (read-byte *the-real-input*))))

(defun bad ()
  (setf (stream-element-type *standard-input*) '(unsigned-byte 8))
  (print
   (loop repeat 10
         collect (read-byte *standard-input*))))
  
exotica$ clisp -norc -q -i /tmp/test.lisp -x '(bad)' < /tmp/data.bz2 
;; Loading file /tmp/test.lisp ...
;; Loaded file /tmp/test.lisp
*** - (SETF STREAM-ELEMENT-TYPE) on #<INPUT STRING-INPUT-STREAM> is
illegal
exotica$ clisp -norc -q -i /tmp/test.lisp -x '(good)' < /tmp/data.bz2 
;; Loading file /tmp/test.lisp ...
;; Loaded file /tmp/test.lisp
(66 90 104 57 49 65 89 38 83 89) 
(66 90 104 57 49 65 89 38 83 89)

I going now to put it all together to see if my cgi script works now.

Thanks.

Thibault

> -------------------------------------------------------
> Enterprise Linux Forum Conference & Expo, June 4-6, 2003, Santa Clara
> The only event dedicated to issues related to Linux enterprise solutions
> www.enterpriselinuxforum.com
> 
> _______________________________________________
> clisp-list mailing list
> [email-masked]
> https://lists.sourceforge.net/lists/listinfo/clisp-list
-- 
Thibault Langlois <[email-masked]>

---

From: Thibault Langlois <[email-masked]>
Date: Wed May 14 10:12:18 2003

> I.e. you have to choose among these, and cannot combine.

There is still something I do not understand:

I put my test in a script file:

exotica$ cat test.cgi
#!/usr/local/bin/clisp -norc -q
(defvar *the-real-input* *standard-input*)

(defun good ()

(defun bad ()

(good)
  
exotica$ test.cgi < /tmp/data.bz2

But when the script is run by httpd it give the same error 
again (from /var/log/httpd/error_log):

*** - (SETF STREAM-ELEMENT-TYPE) on #<IO TERMINAL-STREAM> is illegal
[Wed May 14 17:51:21 2003] [error] [client 194.117.35.226] Premature end
of script headers: /home/tl/www_public/test.cgi

What is wrong ?