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 <[email protected]> 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