History variables: Difference between revisions
Content added Content deleted
(Add Factor example) |
|||
Line 1,098: | Line 1,098: | ||
</pre> |
</pre> |
||
=={{header|Julia}}== |
|||
<lang Julia>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)") |
|||
</lang>{{output}}<pre>Past history of variable x: Number[1, 3, 5]. Current value is 4</pre> |
|||
=={{header|Kotlin}}== |
=={{header|Kotlin}}== |
||
<lang scala>// version 1.1.4 |
<lang scala>// version 1.1.4 |
||
Line 1,137: | Line 1,156: | ||
Currentvalue is 3 |
Currentvalue is 3 |
||
</pre> |
</pre> |
||
=={{header|M2000 Interpreter}}== |
=={{header|M2000 Interpreter}}== |
||
We can make objects type of Group to act as History Variables. Each group has a pointer to a stack object (a linked list). |
We can make objects type of Group to act as History Variables. Each group has a pointer to a stack object (a linked list). |