Skip to content
Permalink
89136f36f6
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
35 lines (32 sloc) 1.01 KB
module WFF
export wordlist
const delims = [' ','\n','\t','.',',','(',')','?','/'] # single quotes: character literal
function getstr(file)
f = open(file)
str = readstring(f)
close(f)
str
end
type wordlist
file::String
words::Dict{String,Int}
string::String
addword::Function
print::Function
function wordlist(file::String)
this = new(file)
this.words = Dict{String,Int}()
this.string = getstr(this.file)
this.addword = function(word)
haskey(this.words, word) ? this.words[word] += 1 : this.words[word] = 1
this.words[word]
end
this.print = function()
println("\nword frequencies for $(this.file)")
[println("\t$kv") for kv in this.words] # word_dicts is object scope!
end
map(word->this.addword(word),split(this.string,delims))
this
end
end
end