0
votes

I am going through Parallel Loops and Maps and I am seeming to have difficulty with even accessing the file count_heads.jl

I saved it in my working directory

function count_heads(n)
    c::Int = 0
    for i = 1:n
        c += rand(Bool)
    end
    c
end

And I can verify it's existence in that directory:

filter(r"count_heads.jl", readdir())
#1-element Array{String,1}:
#"count_heads.jl"

Yet when I attempt the next step in the tutorial.

@everywhere include_string(Main, $(read("count_heads.jl", String)), "count_heads.jl")
ERROR: MethodError: Cannot `convert` an object of type Type{String} to an object of type Array{UInt8,1}
This may have arisen from a call to the constructor Array{UInt8,1}(...),
since type constructors fall back to convert methods.

Looking at just the read("count_heads.jl", String) function I get the source of the error (I think).

1
The code works on my system (julia 0.6 on Mac, testing in Juno) - Michael K. Borregaard
Just read("count_heads.jl", String) gives me "function count_heads(n)\n c::Int = 0\n for i = 1:n\n c += rand(Bool)\n end\n c\nend\n" - Michael K. Borregaard
I was afraid of that. These kind of idiosyncratic errors are really hard to nail down. - Francis Smart

1 Answers

1
votes

You are probably using an older version of Julia (Julia 0.5?). read(filename, String) requires Julia 0.6 or later (https://github.com/JuliaLang/julia/issues/22793).