I’ve been messing around with map
and count
for golfing purposes, and recently noticed this.
julia> map(i->print(i),[1,2,3,4])
12344-element Array{Nothing,1}:
nothing
nothing
nothing
nothing
julia> print(map(i->print(i),[1,2,3,4]))
1234[nothing, nothing, nothing, nothing]
How to explain that array of nothing
s there ?
Edit: Thanks to @jling and @bkamins, I understand both why the above is happening and how to (somewhat) avoid it
Originally, I was trying to evaluate the following function
a(k)=map((i,j)->count(l->l[mod(i+=j,31)+1]=='#',readlines(file)),-k,k)
at k=1,3,5,7
, by doing map(a,[1,3,5,7])
but only the first value of k that I pass in the array prints the correct value, rest all produce 0.
Even if I try to evaluate a
‘normally’ as:
print("$(a(7)) and $(a(3))")
my second call always returns 0. Why is this happening ? (I’m on Julia 1.5.2 btw)