Eli Za=
retskii <
eliz@gnu.org> schrieb am=
Do., 14. Dez. 2017 um 17:28=C2=A0Uhr:
> From: Philipp Stephani <p.stephani2@gmail.com>
> Date: Wed, 13 Dec 2017 22:37:46 +0000
> Cc: emacs-dev=
el@gnu.org
>
> Sounds reasonable, here is a patch.
Thanks.
> -@defun json-parse-string string
> +@defun json-parse-string string &key (object-type 'hash-table=
)
Hmm.. why is there an apostrophe before "hash-table"?=C2=A0 What =
do you
want to get in the output there?
An apo=
strophe? It seems to work as expected.
=C2=A0
And btw, I don't see "&key" mentioned anywhere in the ELi=
sp manual, so
I wonder whether the reader will understand what it means.
=
This is the Common Lisp syntax, from cl-defun etc. It=
39;s a bit unfortunate that it's not used in Emacs core, even for funct=
ions that take keyword arguments such as `make-process'. I can switch t=
o '&rest args' if you prefer that.
=C2=A0
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 case json_object_alist:
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 {
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 result =3D Qnil;
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 const char *key_str;=
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 json_t *value;
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 json_object_foreach =
(json, key_str, value)
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 {
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 Lisp_O=
bject key =3D Fintern (json_build_string (key_str), Qnil);
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 result=
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=
=3D Fcons (Fcons (key, json_to_lisp (value, object_type)),
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0result);
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 }
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 result =3D Fnreverse=
(result);
Is there a reason for calling nreverse here?
It puts the elements in the same order as the original JSON. (The Jan=
sson parser also retains the original order.)
This isn't very=
important, just a bit nicer and less surprising.
=C2=A0
> +The keyword argument OBJECT-TYPE specifies which Lisp type is used to=
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 ^^^^^^^^^^^
Shouldn't that be `:object-type' (including quotes)?
Depending on whether we can use &key in a docstri=
ng in core. If so, then this one is correct, see e.g. the docstring of shou=
ld-error.=C2=A0