Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
crude oop
- Loading branch information
kirk gardner
committed
Apr 3, 2018
1 parent
7553036
commit f3ca692
Showing
1 changed file
with
40 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#!/usr/local/bin/julia | ||
|
||
const files = length(ARGS) == 0 ? (println("please provide at least one file name!"); exit()) : ARGS | ||
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 | ||
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 | ||
map(word->this.addword(word),split(this.string,delims)) | ||
this | ||
end | ||
end | ||
|
||
|
||
file_o = [wordlist(file) for file in files] | ||
for wl in file_o | ||
println("$(typeof(wl)) \"obj\"") | ||
for field in fieldnames(wl) | ||
s = String(field) | ||
println("\n__wl.$(s)__") | ||
println(getfield(wl,Symbol(field))) | ||
end | ||
end |