Skip to content

Commit

Permalink
deprecate old dict syntax and change uses in base and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffBezanson committed Oct 6, 2014
1 parent fd6338d commit 3f1101f
Show file tree
Hide file tree
Showing 37 changed files with 253 additions and 226 deletions.
22 changes: 11 additions & 11 deletions base/LineEdit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ using ..Terminals
import ..Terminals: raw!, width, height, cmove, getX,
getY, clear_line, beep

import Base: ensureroom, peek, show
import Base: ensureroom, peek, show, AnyDict

abstract TextInterface

Expand Down Expand Up @@ -835,7 +835,7 @@ end

const escape_defaults = merge!(
{char(i) => nothing for i=[1:26, 28:31]}, # Ignore control characters by default
{ # And ignore other escape sequences by default
AnyDict( # And ignore other escape sequences by default
"\e*" => nothing,
"\e[*" => nothing,
# Also ignore extended escape sequences
Expand All @@ -856,7 +856,7 @@ const escape_defaults = merge!(
"\eOD" => "\e[D",
"\eOH" => "\e[H",
"\eOF" => "\e[F",
})
))

function write_response_buffer(s::PromptState, data)
offset = s.input_buffer.ptr
Expand Down Expand Up @@ -997,7 +997,7 @@ end

function setup_search_keymap(hp)
p = HistoryPrompt(hp)
pkeymap = {
pkeymap = AnyDict(
"^R" => (s,data,c)->(history_set_backward(data, true); history_next_result(s, data)),
"^S" => (s,data,c)->(history_set_backward(data, false); history_next_result(s, data)),
'\r' => (s,o...)->accept_result(s, p),
Expand Down Expand Up @@ -1066,12 +1066,12 @@ function setup_search_keymap(hp)
edit_insert(data.query_buffer, input); update_display_buffer(s, data)
end,
"*" => (s,data,c)->(edit_insert(data.query_buffer, c); update_display_buffer(s, data))
}
)
p.keymap_func = keymap([pkeymap, escape_defaults])
skeymap = {
skeymap = AnyDict(
"^R" => (s,o...)->(enter_search(s, p, true)),
"^S" => (s,o...)->(enter_search(s, p, false)),
}
)
(p, skeymap)
end

Expand Down Expand Up @@ -1118,7 +1118,7 @@ function commit_line(s)
end

const default_keymap =
{
AnyDict(
# Tab
'\t' => (s,o...)->begin
buf = buffer(s)
Expand Down Expand Up @@ -1226,9 +1226,9 @@ const default_keymap =
edit_insert(s, input)
end,
"^T" => (s,o...)->edit_transpose(s),
}
)

const history_keymap = {
const history_keymap = AnyDict(
"^P" => (s,o...)->(history_prev(s, mode(s).hist)),
"^N" => (s,o...)->(history_next(s, mode(s).hist)),
# Up Arrow
Expand All @@ -1239,7 +1239,7 @@ const history_keymap = {
"\e[5~" => (s,o...)->(history_prev(s, mode(s).hist)),
# Page Down
"\e[6~" => (s,o...)->(history_next(s, mode(s).hist))
}
)

function deactivate(p::Union(Prompt,HistoryPrompt), s::Union(SearchState,PromptState), termbuf)
clear_input_area(termbuf, s)
Expand Down
17 changes: 9 additions & 8 deletions base/REPL.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import Base:
AsyncStream,
Display,
display,
writemime
writemime,
AnyDict

import ..LineEdit:
CompletionProvider,
Expand Down Expand Up @@ -675,9 +676,9 @@ function setup_interface(repl::LineEditREPL; hascolor = repl.hascolor, extra_rep

# Setup history
# We will have a unified history for all REPL modes
hp = REPLHistoryProvider((Symbol=>Any)[:julia => julia_prompt,
:shell => shell_mode,
:help => help_mode])
hp = REPLHistoryProvider(Dict{Symbol,Any}(:julia => julia_prompt,
:shell => shell_mode,
:help => help_mode))
if !repl.no_history_file
try
f = open(find_hist_file(), true, true, true, false, false)
Expand All @@ -704,7 +705,7 @@ function setup_interface(repl::LineEditREPL; hascolor = repl.hascolor, extra_rep
extra_repl_keymap = [extra_repl_keymap]
end

const repl_keymap = {
const repl_keymap = AnyDict(
';' => function (s,o...)
if isempty(s) || position(LineEdit.buffer(s)) == 0
buf = copy(LineEdit.buffer(s))
Expand Down Expand Up @@ -775,14 +776,14 @@ function setup_interface(repl::LineEditREPL; hascolor = repl.hascolor, extra_rep
end
end
end,
}
)

a = Dict{Any,Any}[hkeymap, repl_keymap, LineEdit.history_keymap, LineEdit.default_keymap, LineEdit.escape_defaults]
prepend!(a, extra_repl_keymap)

julia_prompt.keymap_func = LineEdit.keymap(a)

const mode_keymap = {
const mode_keymap = AnyDict(
'\b' => function (s,o...)
if isempty(s) || position(LineEdit.buffer(s)) == 0
buf = copy(LineEdit.buffer(s))
Expand All @@ -801,7 +802,7 @@ function setup_interface(repl::LineEditREPL; hascolor = repl.hascolor, extra_rep
transition(s, :reset)
LineEdit.refresh_line(s)
end
}
)

b = Dict{Any,Any}[hkeymap, mode_keymap, LineEdit.history_keymap, LineEdit.default_keymap, LineEdit.escape_defaults]
prepend!(b, extra_repl_keymap)
Expand Down
8 changes: 4 additions & 4 deletions base/cartesian.jl
Original file line number Diff line number Diff line change
Expand Up @@ -451,10 +451,10 @@ end

## Resolve expressions at parsing time ##

const exprresolve_arith_dict = (Symbol=>Function)[:+ => +,
:- => -, :* => *, :/ => /, :^ => ^, :div => div]
const exprresolve_cond_dict = (Symbol=>Function)[:(==) => ==,
:(<) => <, :(>) => >, :(<=) => <=, :(>=) => >=]
const exprresolve_arith_dict = Dict{Symbol,Function}(:+ => +,
:- => -, :* => *, :/ => /, :^ => ^, :div => div)
const exprresolve_cond_dict = Dict{Symbol,Function}(:(==) => ==,
:(<) => <, :(>) => >, :(<=) => <=, :(>=) => >=)

function exprresolve_arith(ex::Expr)
if ex.head == :call && haskey(exprresolve_arith_dict, ex.args[1]) && all([isa(ex.args[i], Number) for i = 2:length(ex.args)])
Expand Down
4 changes: 2 additions & 2 deletions base/client.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

const ARGS = UTF8String[]

const text_colors = {
const text_colors = AnyDict(
:black => "\033[1m\033[30m",
:red => "\033[1m\033[31m",
:green => "\033[1m\033[32m",
Expand All @@ -14,7 +14,7 @@ const text_colors = {
:white => "\033[1m\033[37m",
:normal => "\033[0m",
:bold => "\033[1m",
}
)

have_color = false
@unix_only default_color_answer = text_colors[:bold]
Expand Down
6 changes: 3 additions & 3 deletions base/combinatorics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ function nextpartition(n, as)
xs
end

let _npartitions = (Int=>Int)[]
let _npartitions = Dict{Int,Int}()
global npartitions
function npartitions(n::Int)
if n < 0
Expand Down Expand Up @@ -424,7 +424,7 @@ function nextfixedpartition(n, m, bs)
return as
end

let _nipartitions = ((Int,Int)=>Int)[]
let _nipartitions = Dict{(Int,Int),Int}()
global npartitions
function npartitions(n::Int,m::Int)
if n < m || m == 0
Expand Down Expand Up @@ -489,7 +489,7 @@ function nextsetpartition(s::AbstractVector, a, b, n, m)

end

let _nsetpartitions = (Int=>Int)[]
let _nsetpartitions = Dict{Int,Int}()
global nsetpartitions
function nsetpartitions(n::Int)
if n < 0
Expand Down
2 changes: 1 addition & 1 deletion base/datafmt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ end

const valid_opts = [:header, :has_header, :ignore_invalid_chars, :use_mmap, :quotes, :comments, :dims, :comment_char, :skipstart, :skipblanks]
const valid_opt_types = [Bool, Bool, Bool, Bool, Bool, Bool, NTuple{2,Integer}, Char, Integer, Bool]
const deprecated_opts = [ :has_header => :header ]
const deprecated_opts = Dict(:has_header => :header)
function val_opts(opts)
d = Dict{Symbol,Union(Bool,NTuple{2,Integer},Char,Integer)}()
for (opt_name, opt_val) in opts
Expand Down
14 changes: 7 additions & 7 deletions base/dates/adjusters.jl
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,13 @@ function DateTime(func::Function,y,m,d,h,mi,s;step::Period=Millisecond(1),negate
end

# Return the next TimeType that falls on dow
ISDAYOFWEEK = [Mon=>DateFunction(ismonday,false,Date(0)),
Tue=>DateFunction(istuesday,false,Date(0)),
Wed=>DateFunction(iswednesday,false,Date(0)),
Thu=>DateFunction(isthursday,false,Date(0)),
Fri=>DateFunction(isfriday,false,Date(0)),
Sat=>DateFunction(issaturday,false,Date(0)),
Sun=>DateFunction(issunday,false,Date(0))]
ISDAYOFWEEK = Dict(Mon=>DateFunction(ismonday,false,Date(0)),
Tue=>DateFunction(istuesday,false,Date(0)),
Wed=>DateFunction(iswednesday,false,Date(0)),
Thu=>DateFunction(isthursday,false,Date(0)),
Fri=>DateFunction(isfriday,false,Date(0)),
Sat=>DateFunction(issaturday,false,Date(0)),
Sun=>DateFunction(issunday,false,Date(0)))

# "same" indicates whether the current date can be considered or not
tonext(dt::TimeType,dow::Int;same::Bool=false) = adjust(ISDAYOFWEEK[dow],same ? dt : dt+Day(1),Day(1),7)
Expand Down
12 changes: 6 additions & 6 deletions base/dates/io.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ end
Base.show(io::IO,x::Date) = print(io,string(x))

### Parsing
const english = (UTF8String=>Int)["january"=>1,"february"=>2,"march"=>3,"april"=>4,
const english = Dict{UTF8String,Int}("january"=>1,"february"=>2,"march"=>3,"april"=>4,
"may"=>5,"june"=>6,"july"=>7,"august"=>8,"september"=>9,
"october"=>10,"november"=>11,"december"=>12]
const abbrenglish = (UTF8String=>Int)["jan"=>1,"feb"=>2,"mar"=>3,"apr"=>4,
"october"=>10,"november"=>11,"december"=>12)
const abbrenglish = Dict{UTF8String,Int}("jan"=>1,"feb"=>2,"mar"=>3,"apr"=>4,
"may"=>5,"jun"=>6,"jul"=>7,"aug"=>8,"sep"=>9,
"oct"=>10,"nov"=>11,"dec"=>12]
const MONTHTOVALUE = (UTF8String=>Dict{UTF8String,Int})["english"=>english]
const MONTHTOVALUEABBR = (UTF8String=>Dict{UTF8String,Int})["english"=>abbrenglish]
"oct"=>10,"nov"=>11,"dec"=>12)
const MONTHTOVALUE = Dict{UTF8String,Dict{UTF8String,Int}}("english"=>english)
const MONTHTOVALUEABBR = Dict{UTF8String,Dict{UTF8String,Int}}("english"=>abbrenglish)

# Date/DateTime Parsing
abstract Slot{P<:AbstractTime}
Expand Down
28 changes: 14 additions & 14 deletions base/dates/query.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ dayofweek(dt::TimeType) = dayofweek(days(dt))

const Monday,Tuesday,Wednesday,Thursday,Friday,Saturday,Sunday = 1,2,3,4,5,6,7
const Mon,Tue,Wed,Thu,Fri,Sat,Sun = 1,2,3,4,5,6,7
const english_daysofweek = [1=>"Monday",2=>"Tuesday",3=>"Wednesday",
4=>"Thursday",5=>"Friday",6=>"Saturday",7=>"Sunday"]
const VALUETODAYOFWEEK = (UTF8String=>Dict{Int,UTF8String})["english"=>english_daysofweek]
const english_daysofweekabbr = [1=>"Mon",2=>"Tue",3=>"Wed",
4=>"Thu",5=>"Fri",6=>"Sat",7=>"Sun"]
const VALUETODAYOFWEEKABBR = (UTF8String=>Dict{Int,UTF8String})["english"=>english_daysofweekabbr]
const english_daysofweek = Dict(1=>"Monday",2=>"Tuesday",3=>"Wednesday",
4=>"Thursday",5=>"Friday",6=>"Saturday",7=>"Sunday")
const VALUETODAYOFWEEK = Dict{UTF8String,Dict{Int,UTF8String}}("english"=>english_daysofweek)
const english_daysofweekabbr = Dict(1=>"Mon",2=>"Tue",3=>"Wed",
4=>"Thu",5=>"Fri",6=>"Sat",7=>"Sun")
const VALUETODAYOFWEEKABBR = Dict{UTF8String,Dict{Int,UTF8String}}("english"=>english_daysofweekabbr)
dayname(dt::Integer;locale::String="english") = VALUETODAYOFWEEK[locale][dt]
dayabbr(dt::Integer;locale::String="english") = VALUETODAYOFWEEKABBR[locale][dt]
dayname(dt::TimeType;locale::String="english") = VALUETODAYOFWEEK[locale][dayofweek(dt)]
Expand Down Expand Up @@ -64,14 +64,14 @@ end
const January,February,March,April,May,June = 1,2,3,4,5,6
const July,August,September,October,November,December = 7,8,9,10,11,12
const Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec = 1,2,3,4,5,6,7,8,9,10,11,12
const english_months = [1=>"January",2=>"February",3=>"March",4=>"April",
5=>"May",6=>"June",7=>"July",8=>"August",9=>"September",
10=>"October",11=>"November",12=>"December"]
const VALUETOMONTH = (UTF8String=>Dict{Int,UTF8String})["english"=>english_months]
const englishabbr_months = [1=>"Jan",2=>"Feb",3=>"Mar",4=>"Apr",
5=>"May",6=>"Jun",7=>"Jul",8=>"Aug",9=>"Sep",
10=>"Oct",11=>"Nov",12=>"Dec"]
const VALUETOMONTHABBR = (UTF8String=>Dict{Int,UTF8String})["english"=>englishabbr_months]
const english_months = Dict(1=>"January",2=>"February",3=>"March",4=>"April",
5=>"May",6=>"June",7=>"July",8=>"August",9=>"September",
10=>"October",11=>"November",12=>"December")
const VALUETOMONTH = Dict{UTF8String,Dict{Int,UTF8String}}("english"=>english_months)
const englishabbr_months = Dict(1=>"Jan",2=>"Feb",3=>"Mar",4=>"Apr",
5=>"May",6=>"Jun",7=>"Jul",8=>"Aug",9=>"Sep",
10=>"Oct",11=>"Nov",12=>"Dec")
const VALUETOMONTHABBR = Dict{UTF8String,Dict{Int,UTF8String}}("english"=>englishabbr_months)
monthname(dt::Integer;locale::String="english") = VALUETOMONTH[locale][dt]
monthabbr(dt::Integer;locale::String="english") = VALUETOMONTHABBR[locale][dt]
monthname(dt::TimeType;locale::String="english") = VALUETOMONTH[locale][month(dt)]
Expand Down
6 changes: 4 additions & 2 deletions base/dict.jl
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,8 @@ end
Dict() = Dict{Any,Any}()
Dict(kv::()) = Dict()

const AnyDict = Dict{Any,Any}

# TODO: this can probably be simplified using `eltype` as a THT (Tim Holy trait)
Dict{K,V}(kv::((K,V)...,)) = Dict{K,V}(kv)
Dict{K }(kv::((K,Any)...,)) = Dict{K,Any}(kv)
Expand All @@ -355,7 +357,7 @@ Dict (ps::Pair...) = Dict{Any,Any}(ps)
Dict(kv) = dict_with_eltype(kv, eltype(kv))
dict_with_eltype{K,V}(kv, ::Type{(K,V)}) = Dict{K,V}(kv)
dict_with_eltype{K,V}(kv, ::Type{Pair{K,V}}) = Dict{K,V}(kv)
dict_with_eltype{K,V}(kv, t) = Dict{Any,Any}(kv)
dict_with_eltype(kv, t) = Dict{Any,Any}(kv)

similar{K,V}(d::Dict{K,V}) = Dict{K,V}()

Expand Down Expand Up @@ -730,7 +732,7 @@ end
type WeakKeyDict{K,V} <: Associative{K,V}
ht::Dict{Any,V}

WeakKeyDict() = new((Any=>V)[])
WeakKeyDict() = new(Dict{Any,V}())
end
WeakKeyDict() = WeakKeyDict{Any,Any}()

Expand Down
4 changes: 2 additions & 2 deletions base/latex_symbols.jl
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ end

# Finally, we also add some symbols manually (at the top) as needed.

const latex_symbols = [
const latex_symbols = Dict(

# manual additions:

Expand Down Expand Up @@ -2535,4 +2535,4 @@ const latex_symbols = [
"\\mtteight" => "𝟾", # mathematical monospace digit 8
"\\mttnine" => "𝟿", # mathematical monospace digit 9

]
)
4 changes: 2 additions & 2 deletions base/loading.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ function find_source_file(file)
end

# Store list of files and their load time
package_list = (ByteString=>Float64)[]
package_list = Dict{ByteString,Float64}()
# to synchronize multiple tasks trying to require something
package_locks = (ByteString=>Any)[]
package_locks = Dict{ByteString,Any}()
require(fname::String) = require(bytestring(fname))
require(f::String, fs::String...) = (require(f); for x in fs require(x); end)

Expand Down
4 changes: 2 additions & 2 deletions base/multi.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1117,7 +1117,7 @@ function launch(manager::LocalManager, np::Integer, config::Dict, resp_arr::Arra
for i in 1:np
io, pobj = open(detach(`$(dir)/$(exename) $exeflags --bind-to $(LPROC.bind_addr)`), "r")
io_objs[i] = io
configs[i] = merge(config, {:process => pobj})
configs[i] = merge(config, AnyDict(:process => pobj))
end

# ...and then read the host:port info. This optimizes overall start times.
Expand Down Expand Up @@ -1279,7 +1279,7 @@ function addprocs_internal(np::Integer;
exename=(ccall(:jl_is_debugbuild,Cint,())==0?"./julia":"./julia-debug"),
sshflags::Cmd=``, manager=LocalManager(), exeflags=``, max_parallel=10)

config={:dir=>dir, :exename=>exename, :exeflags=>`$exeflags --worker`, :tunnel=>tunnel, :sshflags=>sshflags, :max_parallel=>max_parallel}
config = AnyDict(:dir=>dir, :exename=>exename, :exeflags=>`$exeflags --worker`, :tunnel=>tunnel, :sshflags=>sshflags, :max_parallel=>max_parallel)
disable_threaded_libs()

ret = Array(Int, 0)
Expand Down
2 changes: 1 addition & 1 deletion base/pkg/generate.jl
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,6 @@ $(copyright(years,authors))
> of your accepting any such warranty or additional liability.
"""

const LICENSES = [ "MIT" => mit, "BSD" => bsd, "ASL" => asl ]
const LICENSES = Dict("MIT" => mit, "BSD" => bsd, "ASL" => asl)

end # module
6 changes: 3 additions & 3 deletions base/pkg/github.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ module GitHub
import Main, ..Git, ..Dir

const AUTH_NOTE = "Julia Package Manager"
const AUTH_DATA = {
const AUTH_DATA = Dict{Any,Any}(
"scopes" => ["repo"],
"note" => AUTH_NOTE,
"note_url" => "http:https://docs.julialang.org/en/latest/manual/packages/",
}
)

function user()
if !success(`git config --global github.user`)
Expand Down Expand Up @@ -36,7 +36,7 @@ function curl(url::String, opts::Cmd=``)
out, proc = open(`curl -i -s -S $opts $url`,"r")
head = readline(out)
status = int(split(head,r"\s+";limit=3)[2])
header = (String=>String)[]
header = Dict{String,String}()
for line in eachline(out)
if !ismatch(r"^\s*$",line)
(k,v) = split(line, r":\s*"; limit=2)
Expand Down
Loading

0 comments on commit 3f1101f

Please sign in to comment.