error "extra token "School" after end of expression" while using Immutable in Julia

Viewed 367

Can any one help me to correct below code.

immutable School
    subject::Symbol
    nclasses::Intn
    students::Int  # average no. of students per class
end

I am getting below error

syntax: extra token "School" after end of expression
1 Answers

immutable is not a keyword any more, use struct, which is equivalent. If you want a mutable object then use mutable struct. Here are the examples:

struct School_immutable
    subject::Symbol
    nclasses::Int
    students::Int  # average no. of students per class
end

mutable struct School_mutable
    subject::Symbol
    nclasses::Int
    students::Int  # average no. of students per class
end

See https://docs.julialang.org/en/latest/manual/types/#Composite-Types-1 for the details of the concept and https://docs.julialang.org/en/latest/base/base/#struct and https://docs.julialang.org/en/latest/base/base/#mutable%20struct for the documentation of the keyword arguments.

Related