Keywords with colon on the backside?

182 views
Skip to first unread message

tabcom...@gmail.com

unread,
Sep 23, 2016, 4:12:55 PM9/23/16
to Clojure
The last four days have been in exercise in frustration as I have tried four different static site generators, all of which gave me serious fits with one exception: Cryogen.* That has led me consider that it might be a good time to dive into Clojure. Though I am new to Clojure, I've been eyeing it for some time. Reading over numerous examples, there is one thing about reading Clojure code that I find a bit hard to take -- keywords. Take the example of metadata for a Cryogen post:

    {:title  "First Post!"
     :layout :post
     :date   "2016-01-01"
     :tags   ["tag1" "tag3"]}
 
It's perfectly understandable, of course, but I can't help but feel a gut reaction that is should be:

    {title:  "First Post!"
     layout: :post
     date:   "2016-01-01"
     tags:   ["tag1" "tag3"]}

And this is true for what seem to be most uses of keywords. Another example:

    (client/get "http://example.com"
      {:headers {:foo ["bar" "baz"], :eggplant "quux"}})

would just read so much better as:

    (client/get "http://example.com"
      {headers: {foo: ["bar" "baz"], eggplant: "quux"}})

So I was wondering, is there any reason Clojure couldn't also support keywords with a backside colon notation?


*I had only one issue with Cryogen, for which the error message was completely useless. But I was able to work out that I was missing a `:layout` in a post's metadata.

Timothy Baldridge

unread,
Sep 23, 2016, 4:22:04 PM9/23/16
to clo...@googlegroups.com
Almost all of Clojure's reader macros are prefix driven. For example, 'foo quotes the symbol "foo", a string "foo" starts with a prefix quote and terminates with another string. Same for lists (prefixed with a parentheses), vectors, maps, etc. Even var literals #'my-var are prefixed. So it's very natural to keep keywords the same way. The syntax (I think) comes from Ruby although they call keywords "symbols". 

So that would be my rationale for it..it's easy to see by the first character of a term what data structure the term will become (https://en.wikibooks.org/wiki/Learning_Clojure/Reader_Macros). And that's just one of many reasons (without even mentioning backwards compatibility), postfix colons on keywords will never happen. 

Hope that helps a bit, it may take a bit to get used to the syntax, but it'll come with time. Welcome to Clojure, by-the-way. 

Timothy

--
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+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google Groups "Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
“One of the main causes of the fall of the Roman Empire was that–lacking zero–they had no way to indicate successful termination of their C programs.”
(Robert Firth)

tabcom...@gmail.com

unread,
Sep 23, 2016, 5:40:14 PM9/23/16
to Clojure


On Friday, September 23, 2016 at 4:22:04 PM UTC-4, tbc++ wrote:

So that would be my rationale for it..it's easy to see by the first character of a term what data structure the term will become (https://en.wikibooks.org/wiki/Learning_Clojure/Reader_Macros). And that's just one of many reasons (without even mentioning backwards compatibility), postfix colons on keywords will never happen. 


Just to clear, I'm not suggesting that the current notation go away. Breaking backwards compatibility would be nuts, of course. Just wonder if the alternative notation could *also* be supported.

I think I found the relevant source code (https://github.com/clojure/clojure/blob/d274b2b96588b100c70be065f949e1fdc9e7e14d/src/jvm/clojure/lang/LispReader.java#L396). Looking at that it seems at least plausible.


Gregg Reynolds

unread,
Sep 23, 2016, 6:02:51 PM9/23/16
to clo...@googlegroups.com

On Sep 23, 2016 4:40 PM, <tabcom...@gmail.com> wrote:
>
>
>
> On Friday, September 23, 2016 at 4:22:04 PM UTC-4, tbc++ wrote:
>>
>>
>> So that would be my rationale for it..it's easy to see by the first character of a term what data structure the term will become (https://en.wikibooks.org/wiki/Learning_Clojure/Reader_Macros). And that's just one of many reasons (without even mentioning backwards compatibility), postfix colons on keywords will never happen. 
>>
>
> Just to clear, I'm not suggesting that the current notation go away. Breaking backwards compatibility would be nuts, of course. Just wonder if the alternative notation could *also* be supported.
>

anything is possible, except for this. ;)

what should the reader do when it encounters "foo:"?

"Symbols beginning or ending with ':' are reserved by Clojure. A symbol can contain one or more non-repeating ':'s."

note that foo: is not a symbol.

once you get the hang of clojure you will drop the idea that {foo: 1} is more expressive than {:foo 1}.  It's kinda like getting over the parentheses.

gregg

> I think I found the relevant source code (https://github.com/clojure/clojure/blob/d274b2b96588b100c70be065f949e1fdc9e7e14d/src/jvm/clojure/lang/LispReader.java#L396). Looking at that it seems at least plausible.
>
>

> --
> 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
> ---
> You received this message because you are subscribed to the Google Groups "Clojure" group.

> To unsubscribe from this group and stop receiving emails from it, send an email to clojure+u...@googlegroups.com.

John Mastro

unread,
Sep 23, 2016, 7:13:30 PM9/23/16
to clo...@googlegroups.com
Timothy Baldridge <tbald...@gmail.com> wrote:
> The syntax (I think) comes from Ruby although they call keywords "symbols".

The reader syntax for Common Lisp's keywords has the leading colon too.

John

larry google groups

unread,
Oct 13, 2016, 3:22:48 PM10/13/16
to Clojure
Am I correct in saying that this conversation is at least partly related to the question of "Will Clojure ever support reader macros?" And for now the answer is "no". Because with reader macros, programmers could change the meaning of ":".
Reply all
Reply to author
Forward
0 new messages