Intro to julia tutorial: Reduce and Parallel Prefix - DummyArray type definition not working


#1

I am trying to learn Julia and I come across this set of great tutorials.

However, when something in the tutorial went wrong, I am not yet equipped to fix it.

for the prefix notebook, the definition of DummyArray gave out an error syntax: extra token "DummyArray" after end of expression

the definition is as below:

isdefined(:DummyArray) || type DummyArray
    length :: Int
    read :: Vector
    history :: Vector{Any}
    DummyArray(length, read=[], history=[])=new(length, read, history)
end

I tried JuliaBox to run the same code, and it yielded the same error message. I am a bit lost as to what the example is trying to demonstrate and how exactly should I define a type in Julia? is it with type or struct keyword? I tried struct and no luck.


#2

The keyword type got replaced with struct or mutable struct at some distant point in the past. If you use one of these, it should run.

The error is just telling you that, because it reads type as an ordinary variable name, it doesn’t know what to do with a space followed by more code – it expects an = or something.


#3

Many thanks works like a charm!