unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* EOF as datum
@ 2016-07-01  9:44 Pierre Lairez
  2016-07-02  2:39 ` Mark H Weaver
  0 siblings, 1 reply; 5+ messages in thread
From: Pierre Lairez @ 2016-07-01  9:44 UTC (permalink / raw)
  To: guile-user

[-- Attachment #1: Type: text/plain, Size: 593 bytes --]

Dear all,

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 ...))

That would simplify (a little, I admit it is not a great deal) the
processing of input data.
One way I see it to define say ##eof thanks to the hash extend
mechanism. Do I miss something simpler?

Best,

Pierre




[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 473 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: EOF as datum
  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
  2016-07-02  9:22   ` Pierre Lairez
  0 siblings, 2 replies; 5+ messages in thread
From: Mark H Weaver @ 2016-07-02  2:39 UTC (permalink / raw)
  To: Pierre Lairez; +Cc: guile-user

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



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: EOF as datum
  2016-07-02  2:39 ` Mark H Weaver
@ 2016-07-02  9:14   ` Pierre Lairez
  2016-07-02  9:22   ` Pierre Lairez
  1 sibling, 0 replies; 5+ messages in thread
From: Pierre Lairez @ 2016-07-02  9:14 UTC (permalink / raw)
  To: Mark H Weaver; +Cc: guile-user

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: EOF as datum
  2016-07-02  2:39 ` Mark H Weaver
  2016-07-02  9:14   ` Pierre Lairez
@ 2016-07-02  9:22   ` Pierre Lairez
  2016-07-02 10:29     ` Marko Rauhamaa
  1 sibling, 1 reply; 5+ messages in thread
From: Pierre Lairez @ 2016-07-02  9:22 UTC (permalink / raw)
  To: Mark H Weaver; +Cc: guile-user

[-- Attachment #1: Type: text/plain, Size: 1133 bytes --]

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

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 --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: EOF as datum
  2016-07-02  9:22   ` Pierre Lairez
@ 2016-07-02 10:29     ` Marko Rauhamaa
  0 siblings, 0 replies; 5+ messages in thread
From: Marko Rauhamaa @ 2016-07-02 10:29 UTC (permalink / raw)
  To: Pierre Lairez; +Cc: guile-user

Pierre Lairez <pierre.lairez@gmail.com>:

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

Two mathematicians met in the university cafeteria. They exchanged
hellos and started chatting. It turned out one of them had just prepared
a paper and was about to send it out for peer review. He had a draft
copy with him and the friend asked to take a look.

The friend was nodding to himself as he was reading, but then at one
point, he raised his eyebrows and stopped. He asked, "How do you get
this from that?" The first mathematician replied, "Oh, it follows
trivially."

The friend looked surprised, took out a small notepad and a pen from his
breast pocket. He scribbled notes and equations for several minutes.
Then, he put the notepad and pen back in his pocket, and said, "Yeah, it
follows trivially."


Marko



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2016-07-02 10:29 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2016-07-02  9:22   ` Pierre Lairez
2016-07-02 10:29     ` Marko Rauhamaa

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).