[Top][All Lists]

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

Re: EOF as datum

From: Mark H Weaver
Subject: Re: EOF as datum
Date: Fri, 01 Jul 2016 22:39:57 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.95 (gnu/linux)


Pierre Lairez <address@hidden> writes:

> I understand why we cannot use (eof-object) in a “case” statement. For
> example, this will not run as it is meant:
> (case (get-char port)
>     (((eof-object)) ...)
>     (else ...))
> Is is possible to define something like #eof that will be datum and make
> the following work as expected?
> (case (get-char port)
>     ((#eof) ...)
>     (else ...))

We cannot make a 'read'able datum that is an eof object, because of the
API of 'read'.  When 'read' returns an eof object, that means that the
end of file has been reached, and that's how existing callers of 'read'
will interpret such a result.

I would suggest using (ice-9 match) instead, e.g.:

  (match (get-char port)
    ((? eof-object?) 'eof)
    ((or #\a #\b) 'a-or-b)
    (#\c 'c)
    (char 'other-character))

See section 7.7 (Pattern Matching) in the Guile manual.
Does that work for you?


reply via email to

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