<div dir="ltr">You will have to forgive but I am now going to do something which I hate when others do it: comment without really knowing much about the topic. :-)<div><br></div><div>Why not just use option (B) and have the empty object as {[]}? It is always consistent and the empty object is easily from the empty list and empty string. I don't see having the extra tuple should cause any problems, but then again I am no expert.</div>
<div><br></div><div>I would prefer to always have strings in *one* format and not special case keys with atoms sometimes. Otherwise to be certain you would have to match both atom and binary to find key. Unless you *always* use atoms for keys, which could easily explode.</div>
<div><br></div><div>Robert<br><br><div class="gmail_quote">2008/7/29 Hynek Vychodil <span dir="ltr"><<a href="mailto:vychodil.hynek@gmail.com">vychodil.hynek@gmail.com</a>></span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div dir="ltr"><br><br><div class="gmail_quote"><div><div></div><div class="Wj3C7c">On Tue, Jul 29, 2008 at 3:13 AM, Richard A. O'Keefe <span dir="ltr"><<a href="mailto:ok@cs.otago.ac.nz" target="_blank">ok@cs.otago.ac.nz</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="border-left:1px solid rgb(204, 204, 204);margin:0pt 0pt 0pt 0.8ex;padding-left:1ex">
<div>On 29 Jul 2008, at 9:51 am, Paulo Sérgio Almeida wrote:<br>
> I think there is no doubt that lists will be more useful than<br>
> tuples. There is, however another option, that I have been using in<br>
> a json parser I wrote:<br>
><br>
> (C) an object is simply a proplist, i.e. a list of tuples.<br>
<br>
</div>This is in fact what I originally proposed,<br>
the tricky point being that {} is a legal empty object in JSON,<br>
and we can't map that to [] because that's the representation<br>
for the empty sequence [].<br>
<br>
(O) Original proposal: {} => {}, other objects => list of pairs<br>
(A) Armstrong version: object => tuple of pairs, no exceptions.<br>
(B) Object => {list of pairs}.<br>
(C) Almeida proposal: as (O) but {} => [{}].<br>
<br>
The arguments for usability of the result in Erlang are the<br>
arguments that originally had me proposing (O).<br>
<br>
However, I note that nothing stops us providing a range of<br>
handy-dandy functions that work on tuples of pairs.<br>
<br>
%(O)<br>
is_object({}) -> true;<br>
is_object([{_,_}|_]) -> true;<br>
is_object(_) -> false.<br>
<br>
%(A)<br>
is_object(T) -> is_tuple(T).<br>
<br>
%(B)<br>
is_object({T}) -> is_list(T).</blockquote></div></div><div>is_object({T}) -> is_list(T);<br>is_object(_) -> false. % avoid exception<br></div><div class="Ih2E3d"><blockquote class="gmail_quote" style="border-left:1px solid rgb(204, 204, 204);margin:0pt 0pt 0pt 0.8ex;padding-left:1ex">
<br>
<br>
%(C)<br>
is_object([T|_]) -> is_tuple(T);<br>
is_object(_) -> false.<br>
<br>
It's rather annoying to be so bothered about empty objects;<br>
do they occur in practical JSON? Proposal (C) seems neat enough;<br>
the main problem is fitting the results with @type.</blockquote></div><div><br>(C) seems good for me too, because proplist works fine with it.<br><br>> proplists:get_bool(a, [{}]).<br>false<br>> proplists:get_bool(a, [{a, true}]).<br>
true<br>> proplists:get_value(a, [{a, true}]).<br>true<br>> proplists:get_value(a, [{a, heh}]).<br>heh<br>> proplists:get_value(a, [{}]).<br>undefined<br><br>atom is used only for simplicity, but works with binaries too. (JSON's boolean should be true/false atom of course I assume.)<br>
</div><div class="Ih2E3d"><blockquote class="gmail_quote" style="border-left:1px solid rgb(204, 204, 204);margin:0pt 0pt 0pt 0.8ex;padding-left:1ex"><br>
<font color="#888888"><br>
--<br>
If stupidity were a crime, who'd 'scape hanging?<br>
</font><div><div></div><div><br>
<br>
<br>
<br>
<br>
<br>
<br>
_______________________________________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org" target="_blank">erlang-questions@erlang.org</a><br>
<a href="http://www.erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://www.erlang.org/mailman/listinfo/erlang-questions</a><br>
</div></div></blockquote></div></div><br><br clear="all"><br>-- <br>--Hynek (Pichi) Vychodil<br>
</div>
<br>_______________________________________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
<a href="http://www.erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://www.erlang.org/mailman/listinfo/erlang-questions</a><br></blockquote></div><br></div></div>