unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: Mark H Weaver <mhw@netris.org>
To: Pierre Lairez <pierre.lairez@gmail.com>
Cc: guile-user@gnu.org
Subject: Re: EOF as datum
Date: Fri, 01 Jul 2016 22:39:57 -0400	[thread overview]
Message-ID: <877fd44vb6.fsf@netris.org> (raw)
In-Reply-To: <57763B70.8010006@gmail.com> (Pierre Lairez's message of "Fri, 1 Jul 2016 11:44:16 +0200")

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



  reply	other threads:[~2016-07-02  2:39 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 [this message]
2016-07-02  9:14   ` Pierre Lairez
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=877fd44vb6.fsf@netris.org \
    --to=mhw@netris.org \
    --cc=guile-user@gnu.org \
    --cc=pierre.lairez@gmail.com \
    /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).