From c63dc992338091ac6f15ab317f6bffef18950329 Mon Sep 17 00:00:00 2001 From: Simon Kornblith <simon@simonster.com> Date: Wed, 3 Dec 2014 20:18:42 -0500 Subject: [PATCH] Fix #18 --- README.md | 4 ++++ src/Compat.jl | 4 ++++ test/runtests.jl | 3 +++ 3 files changed, 11 insertions(+) diff --git a/README.md b/README.md index c92ed779fa587..a7aa035285634 100644 --- a/README.md +++ b/README.md @@ -51,3 +51,7 @@ Currently, the `@compat` macro supports the following syntaxes: * `itrunc`, `iround`, `iceil`, `ifloor` are now accessed via `trunc(T, x)`, etc. [#9133](https://github.com/JuliaLang/julia/pull/9133) * `Base.Random.randmtzig_exprnd` is now `randexp` [#9144](https://github.com/JuliaLang/julia/pull/9144) + +## Other syntax changes + +* `Dict(ks, vs)` is now `Dict(zip(ks, vs))` [#8521](https://github.com/JuliaLang/julia/pull/8521) diff --git a/src/Compat.jl b/src/Compat.jl index fe863e740f3e3..c4de0e2d5fc71 100644 --- a/src/Compat.jl +++ b/src/Compat.jl @@ -24,6 +24,10 @@ if VERSION < v"0.4.0-dev+980" macro AnyDict(pairs...) esc(Expr(:typed_dict, :(Any=>Any), pairs...)) end + + Base.Dict(kv) = dict_with_eltype(kv, eltype(kv)) + dict_with_eltype{K,V}(kv, ::Type{(K,V)}) = Dict{K,V}(kv) + dict_with_eltype(kv, t) = Dict{Any,Any}(kv) else macro Dict(pairs...) esc(Expr(:call, :Dict, pairs...)) diff --git a/test/runtests.jl b/test/runtests.jl index 3e036ad0b4d3d..e5df72b18dbbc 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -39,6 +39,9 @@ d2[:a] = Dict{Symbol,Int}() d2[:a][:b] = 1 @test @compat(Dict(:a => Dict(:b => 1))) == d2 +d = Dict(zip([1, 2], [3, 4])) +@test d == @compat Dict(1=>3, 2=>4) + @compat function f() a = :a b = Dict(:b => 1)