Email list hosting service & mailing list manager

Re: Some questions and comments on the srfi and its reference implementation Amirouche Boubekki 26 Sep 2021 07:28 UTC

Hello Alejandro,

For some reason I can not find that thread in my mailbox:


Here is the repository with the code of the Gambit implementation:

I quote the original thread and try to answer the question when I can:

> 1. Should the generator produced by json-generator close over the current values
> of json-nesting-depth-limit and json-number-of-character-limit when it is
> created? Consider the example:
> ;; generator created, default parameter values of +inf.0
> (define gen (with-input-from-string "true" json-generator))
> ;; generator used, reference implementation does not raise an error
> (parameterize ((json-number-of-character-limit 1))
>  (gen))

I do not understand the question.

If I could, I would remove the json-number-of-character-limit from
that specification. That is good practice to limit the size of the
input, but it must be done upstream, and not in a JSON library.

> 2. Why is the port-or-accumulator argument to json-accumulator required? I think
> the returned accumulator should default to writing to the current-output-port
> just like json-write does.
> I believe the following are errors in the reference implementation:

That is a mistake, port-or-accumulator or port-or-generator must
always be optional, like you describe.

> 1. The reference implementation of json-generator accepts ONLY an input-port and
> does not accept a character generator as its argument.

That is a mistake in the sample / reference implementation.

> 2. The reference implementation of json-accumulator accepts ONLY an accumulator
> and does not accept an output-port as its argument.

That is another mistake.

> 3. In the reference implementation the accumulator produced by json-accumulator
> expects its input to be pairs such as (cons 'json-value 10) or (cons
> 'json-structure 'array-start). It does not accept the output of generators
> produced by json-generator.

Do you have an example of that? Seems like yet another mistake.

In the gambit repository there is this comment in the README:

> Very large numbers
> Some grammatically valid inputs may cause gambit to perform expensive bignum operations possibly using all available memory. The test data includes one such file “i_number_huge_exp.json” (the test case is commented out).
> Should there be a way to mitigate this risk?

What I was thinking is to add parameters such as
json-maximum-absolute-number. But then what do we do with inexact

I perused some other JSON readers / writers in other languages. They
support NaN, -inf and +inf but those are not in the RFC.