I did not want to argue for or against the "," as whitespace feature, but just
wanted to point out the possible gotchas that we probably should warn novice
clojure programmers for. I actually hit my head when I was trying to initialize
a map with some nil value for :b, like:
user> {:a, "a", :b,, :c, "c"}
; Evaluation aborted.
user>
which yields some ArrayIndexOutOfBoundsException that I guess somehow tries to
tell you that there is an odd number of entries for the map... and indirectly
made me remember about those commas & whitespace.
It would have been a nasty bug if I would have tried to initialize an even
number of nil values, like:
user> {:a,, :b,, :c, "c"}
{:a :b, :c "c"}
instead of
user> {:a, nil,:b, nil, :c, "c"}
{:a nil, :b nil, :c "c"}
as the former expression doesn't barf but simply yields the wrong result...
So, it's all some form of RTFM... but one could argue that this novel use of
commas in the syntax results in adding a little "incidental complexity" to the
language ;-)
-Frank.
On Apr 2, 2010, at 7:39 AM, Per Vognsen wrote:
> Well, for the comma to be useful, it cannot require whitespace
> separation on either side. It would be weird if you had to write [1 ,
> 2 , 3]. So, it shouldn't be surprising that 'list,' is read as 'list'
> when '123,' is read as '123'.
>
> Regarding the strangeness of comma-as-whitespace if you're coming from
> a Lisp background, I admit I initially disliked it but have grown
> fonder of it over time. That was a little surprising to me. I
> generally don't favor syntactic distinctions without a difference,
> e.g. case-insensitive symbol reading in Common Lisp, PLT Scheme's [
> and ] as synonyms for ( and ), etc.
>
> -Per
>
> On Fri, Apr 2, 2010 at 6:10 PM, Mark J. Reed <[email protected]> wrote:
>> try this one:
>> (list,1,2,3)
>> :)
>> Per: I'd say it's also weird if you're coming from a Lisp background - just
>> weird in the opposite direction. But not so weird that it's not useful,
>> mostly for separating key/value pairs from other key/value pairs in a map.
>> It's like Perl's "fat comma" arrow operator in that sense - syntactically
>> no different from comma, but stylistically helpful.
>>
>> On Fri, Apr 2, 2010 at 1:52 AM, Per Vognsen <[email protected]> wrote:
>>>
>>> It doesn't feel right only if you still think you are programming in
>>> an Algol-style language where , is a separator token.
>>>
>>> I can't imagine this is going to change.
>>>
>>> -Per
>>>
>>> On Fri, Apr 2, 2010 at 12:37 PM, Frank Siebenlist
>>> <[email protected]> wrote:
>>>> Even though the specs clearly say that commas are whitespace, the
>>>> following repl session doesn't feel "intuitively" right:
>>>>
>>>> ...
>>>> user> (list 1 2 3)
>>>> (1 2 3)
>>>> user> (list 1, 2, 3)
>>>> (1 2 3)
>>>> user> (list 1, 2, , 3)
>>>> (1 2 3)
>>>> user> (list 1, 2, nil , 3)
>>>> (1 2 nil 3)
>>>> ...
>>>>
>>>> "," is same as ", ," is same as " "... big gotcha for beginning
>>>> clojurians...
>>>>
>>>> Enjoy, Frank.
>>>>
>>>> --
>>>> You received this message because you are subscribed to the Google
>>>> Groups "Clojure" group.
>>>> To post to this group, send email to [email protected]
>>>> Note that posts from new members are moderated - please be patient with
>>>> your first post.
>>>> To unsubscribe from this group, send email to
>>>> [email protected]
>>>> 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 post to this group, send email to [email protected]
>>> Note that posts from new members are moderated - please be patient with
>>> your first post.
>>> To unsubscribe from this group, send email to
>>> [email protected]
>>> For more options, visit this group at
>>> http://groups.google.com/group/clojure?hl=en
>>>
>>> To unsubscribe, reply using "remove me" as the subject.
>>
>>
>>
>> --
>> Mark J. Reed <[email protected]>
>>
>> --
>> You received this message because you are subscribed to the Google
>> Groups "Clojure" group.
>> To post to this group, send email to [email protected]
>> Note that posts from new members are moderated - please be patient with your
>> first post.
>> To unsubscribe from this group, send email to
>> [email protected]
>> 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 post to this group, send email to [email protected]
> Note that posts from new members are moderated - please be patient with your
> first post.
> To unsubscribe from this group, send email to
> [email protected]
> 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 post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en