guile-user
[Top][All Lists]
Advanced

[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:14:58 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.8.0

Hello Mark,

Thanks for your answer, and I see your point concerning the
non-readability of EOF.

And by the way, this point is not so obvious, contrary to what the doc says:
>
> Macro: /SCM/ *SCM_EOF_VAL*
>
>     The Scheme end-of-file value. It has no standard written
>     representation, for obvious reasons.
>
If Guile would read port using stdio rather that libguile/ports, there
would be no problem in reading #<eof>, which is just the immediate value
2564.

Best,

Pierre



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]