Hi Axel,

> Picolisp (pil32 on both linux and cygwin) terminates on Ctrl+D when in
> interactive mode. This is fine, even good. It does however seem like this
> feature is not triggered by a Ctrl+D from the terminal, but rather by EOF
> on stdin.

Actually, the PicoLisp binary never terminates upon Ctrl-D (nor does any
other Unix tool). It is just a convention that the user front end
(typically a shell like 'bash') interprets Ctrl-D typed by the user, and
closes the process's standard input. As a result, the process receives
EOF (read() returns zero), not the ASCII character 4 (Ctrl-D).

(A special case is if PicoLisp is in debug mode (started with the '+').
Then the line editor puts the terminal into raw mode, does its own
keystroke interpretation, and calls (bye) upon Ctrl-D.)


Anyway, as you say, typing Ctrl-D on the console, or receiving EOF from
a pipe should show the same results.


> This may pose a problem. Consider the following example:
> 
> #File: read0.l
> #!/usr/bin/picolisp /usr/lib/picolisp/lib.l
> (in 0
>    (while (peek) (prinl "char: " (char)))
>    (prinl "output text after input eof") )
> (bye)
> 
> 
> 
> #File: readf.l
> #!/usr/bin/picolisp /usr/lib/picolisp/lib.l
> (in '/proc/self/fd/0
>    (while (peek) (prinl "char: " (char)))
>    (prinl "output text after input eof") )
> (bye)
> 
> 
> 
> #Transcript:
> 
> ~$ echo ab|./readf.l
> char: a
> char: b
> char:
> 
> output text after input eof
> ~$ echo ab|./read0.l
> char: a
> char: b
> char: ~$

Strange, I cannot see this behavior of "read0.l". Instead, I get the
same output as for "readf.l". Tried on pil32, pil64, emu, mini and even
ersatz.


> Is there a preferred way of reading stdin aside from opening it on another
> file descriptor as above?

This looks all right. The "official" way is

   (in NIL
      ...

but this is internally the same as

   (in 0
      ...

(assuming that STDIN_FILENO is zero). 'NIL' is the only way in
miniPicoLisp, as it doesn't support numeric file descriptors.

♪♫
- Alex
-- 
UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe

Reply via email to