Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
executable file 26 lines (20 sloc) 944 Bytes
#!/usr/local/bin/julia
const DEF = "tests/one.txt"
const files = length(ARGS) == 0 ? (println("please provide at least one file name!\n > RUNNING $DEF"); [DEF]) : ARGS
const delims = [' ','\n','\t','.',',','(',')','?','/'] # single quotes: character literal
addword!(d,word) = haskey(d, word) ? d[word] += 1 : d[word] = 1
function findwords(file)
d = Dict{String,Int}()
println("reading $(file)")
open(file) do f
map(word->addword!(d,word),split(readstring(f),delims)) # example using map function
# findwords(file) = [addword!(d,word) for word in split(readstring(f),delims)]
end
d # if no return statement last line is returned
end
word_dicts = Dict(file=>findwords(file) for file in files) # as dict list comprehension
function printwords(file)
println("\nword frequencies for $file")
[println("\t$kv") for kv in word_dicts[file]] # word_dicts is in global scope!
end
map(printwords,files)