gcl-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Gcl-devel] stream_at_end EOF diff -Naur patch


From: Camm Maguire
Subject: [Gcl-devel] stream_at_end EOF diff -Naur patch
Date: Thu, 10 Jul 2014 14:14:37 -0400

Greetings!  The problem is, the spec clearly states that there needs to
be an error unless the third argument to read-char-no-hang is nil.  I've
copied the spec below.

The good news is, you can get what you want without having to patch
gcl.  Consider the following modification of the test-it function from
the spec:

(defun test-it (&optional (s *standard-input*) (eof-error-p t) eof)
   (unread-char (read-char s eof-error-p eof) s)
   (list (read-char-no-hang s eof-error-p eof) 
         (read-char-no-hang s eof-error-p eof) 
         (read-char-no-hang s eof-error-p eof)))

A file /tmp/g with one character 'f then gives the following:

>(with-open-file (s "/tmp/g") (test-it s))

Condition in TEST-IT [or a callee]: INTERNAL-SIMPLE-STREAM-ERROR: 
Stream error on stream #<input stream "/tmp/g">: Unexpected end of #<input 
stream "/tmp/g">.

Broken at INVOKE-DEBUGGER.  Type :H for Help.
 1 (Abort) Return to top level.
dbl:>>


>(with-open-file (s "/tmp/g") (test-it s nil 'eof))

(#\f EOF EOF)

In sum, I think you should just append nil and 'eof as the third and
fourth arguments of read-char-no-hang, and all should work.

Please let me know if this is not the case for some reason.

Take care,
=============================================================================
Function READ-CHAR-NO-HANG

Syntax:

read-char-no-hang &optional input-stream eof-error-p eof-value recursive-p => 
char

Arguments and Values:

input-stream -- an input stream designator. The default is standard input.

eof-error-p---a generalized boolean. The default is true.

eof-value---an object. The default is nil.

recursive-p---a generalized boolean. The default is false.

char---a character or nil or the eof-value.

Description:

read-char-no-hang returns a character from input-stream if such a character is 
available. If no character is available, read-char-no-hang returns 
nil.

If recursive-p is true, this call is expected to be embedded in a higher-level 
call to read or a similar function used by the Lisp reader.

If an end of file[2] occurs and eof-error-p is false, eof-value is returned.

Examples:

;; This code assumes an implementation in which a newline is not
;; required to terminate input from the console.
 (defun test-it ()
   (unread-char (read-char))
   (list (read-char-no-hang) 
         (read-char-no-hang) 
         (read-char-no-hang)))
=>  TEST-IT
;; Implementation A, where a Newline is not required to terminate
;; interactive input on the console.
 (test-it)
>>  a
=>  (#\a NIL NIL)
;; Implementation B, where a Newline is required to terminate
;; interactive input on the console, and where that Newline remains
;; on the input stream.
 (test-it)
>>  a<NEWLINE>
=>  (#\a #\Newline NIL)

Affected By:

*standard-input*, *terminal-io*.

Exceptional Situations:

If an end of file[2] occurs when eof-error-p is true, an error of type 
end-of-file is signaled .

See Also:

listen

Notes:

read-char-no-hang is exactly like read-char, except that if it would be 
necessary to wait in order to get a character (as from a keyboard), nil is
immediately returned without waiting.
=============================================================================
-- 
Camm Maguire                                        address@hidden
==========================================================================
"The earth is but one country, and mankind its citizens."  --  Baha'u'llah



reply via email to

[Prev in Thread] Current Thread [Next in Thread]