RosettaCodeData/Task/History-variables/Julia/history-variables.julia
2023-07-01 13:44:08 -04:00

15 lines
322 B
Text

mutable struct Historied
num::Number
history::Vector{Number}
Historied(n) = new(n, Vector{Number}())
end
assign(y::Historied, z) = (push!(y.history, y.num); y.num = z; y)
x = Historied(1)
assign(x, 3)
assign(x, 5)
assign(x, 4)
println("Past history of variable x: $(x.history). Current value is $(x.num)")