History variables: Difference between revisions
Content added Content deleted
(Added Rust) |
(Added Algol W) |
||
Line 189: | Line 189: | ||
<pre>one oneone three |
<pre>one oneone three |
||
14</pre> |
14</pre> |
||
=={{header|ALGOL W}}== |
|||
Algol W does not have history variables as standard, as with other languages here, we can add them using a simple linked list. |
|||
<br>As Algol W does not have generic types, a separate history variable type would be required for each type of variable. |
|||
<lang algolw>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.</lang> |
|||
{{out}} |
|||
<pre> |
|||
hv history: 3 2 1 |
|||
Sum of the historic values: 6 |
|||
</pre> |
|||
=={{header|AspectJ}}== |
=={{header|AspectJ}}== |