Could be my favourite improvement in 1.4

566 views
Skip to first unread message

Daniel Gagnon

unread,
Dec 19, 2011, 11:42:41 PM12/19/11
to clo...@googlegroups.com
Allow colon as whitespace in map literals

That's a very subtle subtle change but with this it will be easier to experiment with JSON or Python data I want to just grab and paste.

That attention to little detail is very appreciated.

Phil Hagelberg

unread,
Dec 20, 2011, 12:25:48 AM12/20/11
to clo...@googlegroups.com

JSON as readable Clojure was discussed and shot down a while back, albeit with a weirder implementation: http://groups.google.com/group/clojure-dev/browse_thread/thread/5b066af1224efe8e/9ae78e878f873058 The idea of colons having special treatment in the context of maps is rather distasteful to me personally.

-Phil

Alan Malloy

unread,
Dec 20, 2011, 2:05:11 AM12/20/11
to Clojure
On Dec 19, 9:25 pm, Phil Hagelberg <p...@hagelb.org> wrote:
> JSON as readable Clojure was discussed and shot down a while back, albeit
> with a weirder implementation:http://groups.google.com/group/clojure-dev/browse_thread/thread/5b066...

> idea of colons having special treatment in the context of maps is
> rather distasteful to me personally.
>
> -Phil

I agree, this horrifies me. It isn't even as simple as "letting them
be whitespace", because presumably you want (read-string "{a: b}") to
result in (hash-map 'a 'b), but (read-string "{a :b}") to result in
(hash-map 'a :b). So you can't just say they're whitespace - you have
to recognize the context they're in to decide what they attach to, if
anything. The existing behavior is much cleaner.

Cedric Greevey

unread,
Dec 20, 2011, 5:02:01 AM12/20/11
to clo...@googlegroups.com

+1

Alex Baranosky

unread,
Dec 20, 2011, 7:36:35 AM12/20/11
to clo...@googlegroups.com
For what it's worth, I think colon's as whitespace in maps adds confusion, without, imo adding a ton of power or readability.  In terms of power, it gives you the ability to paste JSON into a Clojure REPL; I wonder how often that use case comes up?  In terms of readability, any benefit it gives you in readability would be counterweighted by the additional syntax rules it adds.

The only way I could see this as worth it, would be if people wanted to paste 'foreign' map data into a Clojure REPL a ton more frequently than I imagine they do.

Alex

jweiss

unread,
Dec 20, 2011, 8:28:59 AM12/20/11
to Clojure
Even if they did, it's pretty easy to surround the paste with (read-
json "... ").

On Dec 20, 10:36 am, Alex Baranosky <alexander.barano...@gmail.com>
wrote:

Laurent PETIT

unread,
Dec 20, 2011, 8:37:34 AM12/20/11
to clo...@googlegroups.com
Anyway, the issue has not even the start of an argumentation, use
case, or whatever ...

2011/12/20 jweiss <jeffrey...@gmail.com>:

> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clo...@googlegroups.com
> Note that posts from new members are moderated - please be patient with your first post.
> To unsubscribe from this group, send email to
> clojure+u...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en

Alan Malloy

unread,
Dec 20, 2011, 1:29:26 PM12/20/11
to Clojure
Well, that would be sufficient if we had HEREDOCs like Alex asked for,
but surrounding some JSON with ""s will usually break.

Julien Kirch

unread,
Dec 20, 2011, 7:39:55 AM12/20/11
to clo...@googlegroups.com
for these cases wouldn't be simpler to paste the map in a string and to create a function that could parse such a json-compatible map into a clojure map ?

A.

Tavis Rudd

unread,
Jan 16, 2012, 1:19:55 PM1/16/12
to clo...@googlegroups.com
This issue could be avoided by only treating a colon as whitespace when followed by a comma. As easy cut-paste of json seems to be the key motivation here, the commas are going to be there anyway: valid {"v":, 1234} vs syntax error {a-key: should-be-a-keyword}.

Alex Baranosky

unread,
Jan 16, 2012, 10:27:26 PM1/16/12
to clo...@googlegroups.com
This seems like a strange special case. 

What percentage of users need to paste JSON into the REPL?
Of those users, what percentage of the time do they need to do this?


On Mon, Jan 16, 2012 at 1:19 PM, Tavis Rudd <tavis...@gmail.com> wrote:
This issue could be avoided by only treating a colon as whitespace when followed by a comma. As easy cut-paste of json seems to be the key motivation here, the commas are going to be there anyway: valid {"v":, 1234} vs syntax error {a-key: should-be-a-keyword}.

--

Justin Steward

unread,
Jan 16, 2012, 5:23:06 PM1/16/12
to clo...@googlegroups.com
On Tue, Jan 17, 2012 at 5:19 AM, Tavis Rudd <tavis...@gmail.com> wrote:
> {"v":, 1234}

Except that's not valid JSON, so it's still not a simple cut and paste
solution. I personally think that confusing a colon with whitespace
under any circumstances is an unnecessary confusion leading to
unnecessary errors.

~Justin

Tavis Rudd

unread,
Jan 18, 2012, 3:43:00 PM1/18/12
to Clojure


On Jan 16, 2:23 pm, Justin Steward <althalu...@gmail.com> wrote:
> On Tue, Jan 17, 2012 at 5:19 AM, Tavis Rudd <tavis.r...@gmail.com> wrote:
> > {"v":, 1234}
>
> Except that's not valid JSON, so it's still not a simple cut and paste
> solution. I personally think that confusing a colon with whitespace
> under any circumstances is an unnecessary confusion leading to
> unnecessary errors.
>
> ~Justin

Er, brain fart. I was typing faster than I was thinking and put the
comma in the wrong place. In my head I meant the form following the
colon would have to have a comma after it. Thus, {"a-json-key":
1234, ...} would be valid while {"a-json-key": was-supposed-to-be-a-
keyword "another-json-key" foo} would complain about the colon being
an Invalid Token. I don't see the need for it, however. Search and
replace is just as easy as cut and paste.

Jonathan Cardoso

unread,
Jan 18, 2012, 5:52:12 PM1/18/12
to clo...@googlegroups.com
brain fart lol

Jeremy Heiler

unread,
Jan 19, 2012, 2:50:54 PM1/19/12
to clo...@googlegroups.com
On Tue, Dec 20, 2011 at 2:05 AM, Alan Malloy <al...@malloys.org> wrote:
> I agree, this horrifies me. It isn't even as simple as "letting them
> be whitespace", because presumably you want (read-string "{a: b}") to
> result in (hash-map 'a 'b), but (read-string "{a :b}") to result in
> (hash-map 'a :b). So you can't just say they're whitespace - you have
> to recognize the context they're in to decide what they attach to, if
> anything. The existing behavior is much cleaner.

+2

Jonathan Fischer Friberg

unread,
Oct 10, 2012, 10:18:09 AM10/10/12
to clo...@googlegroups.com

+3
 
Reply all
Reply to author
Forward
0 new messages