There is no need to write the type over and over again. You can say
const D = Dict{Symbol, Any}
D(:a => "", :b => 0, ...)
The old syntax for this was
(Symbol=>Any)[:a => "", :b => 0, ...]
but there was no way to abstract over the type part, `(Symbol=>Any)`,
so you really did have to write the types over and over again. The `{
}` syntax only constructed dicts of exactly one type, Dict{Any,Any}.
Do we really want to use an entire set of brackets for exactly one
very-loosely-typed kind of dict?
So in other words there was a "syntax cliff", where you could start
with a bunch of nested `{ }`, but then if you realized every key was
the same type you would have to rewrite everything, switching `{ }` to
`[ ]` and inserting `(T=>S)` in front. Now you can just change the
definition of `const D = ...` in one place.
On Thu, Sep 3, 2015 at 10:12 AM, Mike Nolta <[email protected]> wrote:
> I also think ditching {} for dicts wasn't a great idea.
>
> -Mike
>
> On Thu, Sep 3, 2015 at 9:36 AM, Jonathan Malmaud <[email protected]> wrote:
>> I agree that syntactic sugar for Dict literal construction would be
>> appreciated. There were good reasons for removing the previous syntax, but I
>> think it should be possible to find something more terse than the status
>> quo.
>>
>> On Wednesday, September 2, 2015 at 12:45:08 PM UTC-4, Michael Francis wrote:
>>>
>>> With the change to 0.4 happening soon I'm finding the the new Dict syntax
>>> in 0.4 (removal of {}, []) is extremely verbose.
>>>
>>> I find myself interfacing with JSON APIs frequently, for example a
>>> configuration dictionary :
>>>
>>> data = {
>>> :displayrows => 20,
>>> :cols => [
>>> { :col => "l1" },
>>> { :col => "l2" },
>>> { :col => "l3" },
>>> { :col => "num", :display => true },
>>> { :col => "sum", :display => true, :conf => { :style
>>> => 1, :func => { :method => "sum", :col => "num" } } }
>>> ]
>>> ... # Lots more
>>> }
>>>
>>> becomes -
>>>
>>> data = Dict{Symbol,Any}(
>>> :displayrows => 20,
>>> :cols => [
>>> Dict{Symbol,Any}( :col => "l1" ),
>>> Dict{Symbol,Any}( :col => "l2" ),
>>> Dict{Symbol,Any}( :col => "l3" ),
>>> Dict{Symbol,Any}( :col => "num", :display => true ),
>>> Dict{Symbol,Any}( :col => "sum", :display => true,
>>> :conf => Dict{Symbol,Any}( :style => 1,
>>> :func
>>> => Dict{Symbol,Any}( :method => "sum", :col => "num" ) ) )
>>> ]
>>> ... # Lots more
>>> )
>>>
>>> This feels like asking a person using arrays to write the following
>>>
>>> Array{Int64,2}( Vector{Int64}( 1,2,3), Vector{Int64}( 4,5,6) )
>>>
>>> vs
>>>
>>> [ [ 1, 2, 3] [ 4,5,6 ] ]
>>>
>>> Can we please reconsider ?
>>>
>>