[Top][All Lists]

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

Re: EOF as datum

From: Pierre Lairez
Subject: Re: EOF as datum
Date: Sat, 2 Jul 2016 11:22:33 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.8.0

No, forget what I just wrote, this is obvious.


On 02/07/2016 04:39, Mark H Weaver wrote:
> Hi,
> 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?
>     Regards,
>       Mark

Attachment: signature.asc
Description: OpenPGP digital signature

reply via email to

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