From: Pierre Lairez <pierre.lairez@gmail.com>
To: Mark H Weaver <mhw@netris.org>
Cc: guile-user@gnu.org
Subject: Re: EOF as datum
Date: Sat, 2 Jul 2016 11:14:58 +0200 [thread overview]
Message-ID: <57778612.6000109@gmail.com> (raw)
In-Reply-To: <877fd44vb6.fsf@netris.org>
[-- Attachment #1: Type: text/plain, Size: 1575 bytes --]
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 <pierre.lairez@gmail.com> 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 #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 473 bytes --]
next prev parent reply other threads:[~2016-07-02 9:14 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-07-01 9:44 EOF as datum Pierre Lairez
2016-07-02 2:39 ` Mark H Weaver
2016-07-02 9:14 ` Pierre Lairez [this message]
2016-07-02 9:22 ` Pierre Lairez
2016-07-02 10:29 ` Marko Rauhamaa
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/guile/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=57778612.6000109@gmail.com \
--to=pierre.lairez@gmail.com \
--cc=guile-user@gnu.org \
--cc=mhw@netris.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).