How to resolve the algorithm History variables step by step in the ALGOL W programming language
How to resolve the algorithm History variables step by step in the ALGOL W 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 ALGOL W programming language
Source code in the algol programming language
begin
% implements integer history variables %
% similar history types could be defined for other types of variable %
record HInteger ( integer iValue; reference(HInteger) iPrev );
% sets the latest value of hv to n %
procedure setIhv ( reference(HInteger) value result hv; integer value n ) ; hv := HInteger( n, hv );
% declare an integer history variable %
reference(HInteger) hv;
% initialise the history to a null value %
hv := null;
% assign three values %
setIhv( hv, 1 );
setIhv( hv, 2 );
setIhv( hv, 3 );
% show the history of hv %
begin
reference(HInteger) h;
write( "hv history: " );
h := hv;
while h not = null do begin
writeon( i_w := 3, s_w := 0, iValue(h), " " );
h := iPrev(h)
end while_h_ne_null
end;
% remove the values from hv, summing them as in the Ada sample %
begin
integer s;
s := 0;
while hv not = null do begin
s := s + iValue(hv);
hv := iPrev(hv)
end while_hv_ne_null ;
write( "Sum of the historic values: ", s )
end
end.
You may also check:How to resolve the algorithm File size step by step in the Delphi programming language
You may also check:How to resolve the algorithm Loops/For step by step in the FOCAL programming language
You may also check:How to resolve the algorithm Munchausen numbers step by step in the Perl programming language
You may also check:How to resolve the algorithm Regular expressions step by step in the Julia programming language
You may also check:How to resolve the algorithm Scope modifiers step by step in the Racket programming language