guile-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Including sjson (formerly (ice-9 json)) and fash.scm in guile proper


From: Mark H Weaver
Subject: Re: Including sjson (formerly (ice-9 json)) and fash.scm in guile proper?
Date: Tue, 20 Jun 2017 19:18:35 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.2 (gnu/linux)

I wrote:

> I was also looking for a cleaner way to express this parser, and to add
> better error reporting, while allowing flexibility for users to
> customize the Scheme representation.

I forgot to mention that another goal was to minimize heap allocations,
e.g. eliminating the allocation of intermediate lists of characters or
digits.

>   (define (read-array port)
>     "Read a JSON array from PORT and return the result of calling
> ARRAY-FINALIZE on the final seed produced using ARRAY-KNIL and
> ARRAY-KONS."
>     (match-next* port
>       (#\[ (match-next* port
>              (#\] array-knil)
>              (else (let ((seed (read-array-elements array-knil port)))
>                      (match-next* port
>                        (#\] (array-finalize seed)))))))))

Sorry, I forgot to apply 'array-finalize' in the empty-array case.
Here's a corrected version:

  (define (read-array port)
    "Read a JSON array from PORT and return the result of calling
ARRAY-FINALIZE on the final seed produced using ARRAY-KNIL and
ARRAY-KONS."
    (array-finalize
     (match-next* port
       (#\[ (match-next* port
              (#\] array-knil)
              (else (let ((seed (read-array-elements array-knil port)))
                      (match-next* port
                        (#\] seed)))))))))

      Mark



reply via email to

[Prev in Thread] Current Thread [Next in Thread]