I’m trying to use count
where the iterator is taken from zip
.
Here is the code I’ve written:
function hamming(c, d)
count((x,y) -> (x != y), zip(c,d))
end
However, when this is run on any non-empty collections, e.g. hamming("123","1X3")
, an exception is thrown:
ERROR: MethodError: no method matching (::getfield(Main, Symbol(“##9#10”)))(::Tuple{Char,Char})
Closest candidates are:
#9(::Any, ::Any) at REPL[71]:2
Stacktrace:
[1] count( ::getfield(Main, Symbol(“##9#10”)), ::Base.Iterators.Zip{Tuple{String,String}} ) at ./reduce.jl:772
[2] hamming( ::String, ::String ) at ./REPL[71]:2
[3] top-level scope at REPL[72]:1
I can’t see any obvious reason this wouldn’t work based on the documentation for count()
.
There is also no problem when count
is replaced by an equivalent for
loop, something like:
for (x,y) in zip("123","1X3")
print(x == y ? 0 : 1)
end
Can someone help me out? What have I misunderstood?