EOF handling John Cowan (18 Jan 2020 22:01 UTC)
Re: EOF handling Amirouche Boubekki (21 Jan 2020 10:39 UTC)
Re: EOF handling John Cowan (21 Jan 2020 17:09 UTC)
Re: EOF handling, and reading zero/one/many values Lassi Kortela (21 Jan 2020 22:33 UTC)

Re: EOF handling, and reading zero/one/many values Lassi Kortela 21 Jan 2020 22:33 UTC

>>> I propose that if json-reader gets an eof-object before reading
>>> any part of a JSON value, that it return the eof-object.
>>
>> What is the rationale?
>
> To allow you to create a loop that reads multiple JSON representations
> from an input stream and has a clear way to terminate the loop rather
> than having to catch an exception.

Agreed. These cases would be useful to support with standard procedures:

1. Read at most one JSON value from port.
    - Return eof-object if there are no values.

2. Read exactly one JSON value from port.
    - Error if there are no values.
    - Error if there is more than one value.

The natural implementation of 2 is a simple wrapper around 1, so it's
nice to expose 1 to users of the library as well.

This may be too fancy:

3. Read all JSON values from port and return them as a list.
    - Return empty list if there are no values.

The natural name for procedure 2 is `json-read`, which is in the current
draft (though the draft doesn't say what the procedure does if it
encounters end-of-file or more than one value).

One natural name for procedure 1 is `json-read?` with a question mark,
by analogy to the question mark in regexps. Scheme uses ? for
predicates, so it can be a bit misleading. Another possible name:
`json-read-maybe`.

Or procedure 1 could be called `json-read` (after all, Scheme `read`
returns eof-object if it doesn't find any more data). And procedure 2
could then be called `json-read-one` or `json-read-1` or something.