How to resolve the algorithm History variables step by step in the Elena programming language
How to resolve the algorithm History variables step by step in the Elena programming language
Table of Contents
Problem Statement
Storing the history of objects in a program is a common task. Maintaining the history of an object in a program has traditionally required programmers either to write specific code for handling the historical data, or to use a library which supports history logging. History variables are variables in a programming language which store not only their current value, but also the values they have contained in the past. Some existing languages do provide support for history variables. However these languages typically have many limits and restrictions on use of history variables.
[http://www.bod.com/index.php?id=3435&objk_id=148050 "History Variables: The Semantics, Formal Correctness, and Implementation of History Variables in an Imperative Programming Language" by Mallon and Takaoka] Concept also discussed on LtU and Patents.com. Demonstrate History variable support: For extra points, if the language of choice does not support history variables, demonstrate how this might be implemented.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm History variables step by step in the Elena programming language
Source code in the elena programming language
import extensions;
import system'collections;
import system'routines;
import extensions'routines;
class HistoryVariable
{
Stack previous := new Stack();
object value;
Value
{
get() = value;
set(value)
{
if ((this value) != nil)
{
previous.push(this value)
};
this value := value
}
}
undo()
{
ifnot (previous.isEmpty())
{
value := previous.pop()
}
else
{
value := nil
}
}
enumerator() => previous;
string toPrintable() => this value;
}
public program()
{
var o := new HistoryVariable();
o.Value := 5;
o.Value := "foo";
o.Value := o.Value + "bar";
console.printLine(o);
o.forEach:printingLn;
o.undo().undo().undo();
console.printLine(o.Value ?? "nil")
}
You may also check:How to resolve the algorithm Binary search step by step in the Crystal programming language
You may also check:How to resolve the algorithm Factors of a Mersenne number step by step in the zkl programming language
You may also check:How to resolve the algorithm Hello world/Text step by step in the Extended BrainF*** programming language
You may also check:How to resolve the algorithm String comparison step by step in the Phix programming language
You may also check:How to resolve the algorithm Determine if a string is collapsible step by step in the Scala programming language