just some simple beginners question:

*1. Question:* Why does *Array{AbstractString,1}*: not work?

ERROR: LoadError: MethodError: `commonprefix` has no method matching 
commonprefix(::Array{ASCIIString,1})


function commonprefix(str_arr::Array{AbstractString,1})
    min_idx = indmin(str_arr)
    common_prefix = str_arr[min_idx]
    common_length = length(common_prefix)
    # Other code skipped
    return common_length
end

common_endidx = commonprefix(["/home/Downloads/test", 
"/home/Downloads/othertest"])
println("AbstractString: $common_endidx")






*2. Question:* is there an easy way to avoid rewriting most of the 
functions code



function commonprefix(str_arr::Array{ASCIIString,1})
    min_idx = indmin(str_arr)
    common_prefix = str_arr[min_idx]
    common_length = length(common_prefix)
    # Other code skipped
    return common_length
end

function commonprefix(str_arr::Array{UTF8String,1})
    min_idx = indmin(str_arr)
    common_prefix = str_arr[min_idx]
    common_length = length(common_prefix)
    # Other code skipped
    return common_length
end


# ASCIIString
common_endidx = commonprefix(["/home/Downloads/test", 
"/home/Downloads/othertest"])
println("ASCIIString: $common_endidx")
# UTF8String
common_endidx = commonprefix(["/home/Downloads/átomos", 
"/home/Downloads/otherátomos"])
println("UTF8String: $common_endidx")



Thanks


Reply via email to