[Top][All Lists]

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

Re: [PATCH] json: Add support for encoding structs

From: Stefan Monnier
Subject: Re: [PATCH] json: Add support for encoding structs
Date: Thu, 27 Apr 2017 08:31:08 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.50 (gnu/linux)

>> FWIW, while you can make this work, I think it's a bad API: Elisp
>> usually behaves like "an absent argument is equivalent to nil", and it's
>> easier for the coder if we stick to this behavior (also, occasionally
>> it's handy to be able to use ":key nil" in order not to pass :key).
> Fair point, I was thinking that slot opts aren't exactly an API, so this
> was an exception.

That's the point: it would be an exception.
There are a few places where we distinguish "absence" from nil, and in
my experience these are better avoided.

>>> IIRC, the empty string is a valid JSON key (`JSON.parse(`{"":1}`)`
>>> works in JS).  Symbols are also considered a valid type according to
>>> `json-encode-key'.
>> I don't see why that forces us to also accept symbols here.
> Wouldn't it be consistent to allow symbols in both `json-encode' and
> `json-encode-key`?

I don't see how that's relevant: we're talking about the thing that
follows :json (or somesuch) in a cl-defstruct, not a call to some json
encoding function.


reply via email to

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