From what I can tell these functions do nothing. To use the first one as an example, "drymass(::SmallTank) = 40.0 ". I don’t understand the part inside the parenthesis. I know the “::SmallTank” has to do with typing, but I can’t figure out what it means without a variable. Also, assigning the whole bit to 40.0 seems odd. I suppose that would mean 40.0 is the default amount for the drymass of a SmallTank, but without a parameter it seems to do nothing.
This is just the start of chapter eight. There’s more code to follow, too much to paste here. If anyone has the book and understands whats going on, I would be greatful to have this mystery solved.
Functions like this define the equivalent of class-level constants in other languages, we are saying that every SmallTank has a drymass of 40.0, and any specifics about the tank passed in don’t matter – we only need the type of the variable.
Here’s how you’d use it:
julia> abstract type Tank end
julia> mutable struct SmallTank <: Tank
propellant::Float64
end
julia> x = SmallTank(5.0) # The value here is irrelevant
SmallTank(5.0)
julia> drymass(::SmallTank) = 40.0
drymass (generic function with 1 method)
julia> drymass(x)
40.0
Thanks for the help. I believe I figured out my problem. A rookie mistake.
I was not paying attention to what the getters (seems like they should be called setters) where doing. The drymass is the weight of the tank when empty. The totalmass is the weight of the tank when full. So these amounts are basically constants and should not change. But the tank has three sizes, each with different specifications. By creating functions in this matter the different tank sizes can be selected by the code without using a bunch of if / else statements.
Now that I see what’s happening, it seems pretty simple.