Data update
This commit is contained in:
parent
5150844a7d
commit
4bb20c9b71
7735 changed files with 38060 additions and 199180 deletions
|
|
@ -1,34 +0,0 @@
|
|||
private with Ada.Containers.Indefinite_Vectors;
|
||||
generic
|
||||
type Item_Type (<>) is private;
|
||||
package History_Variables is
|
||||
|
||||
type Variable is tagged limited private;
|
||||
|
||||
-- set and get current value
|
||||
procedure Set(V: in out Variable; Item: Item_Type);
|
||||
function Get(V: Variable) return Item_Type;
|
||||
|
||||
-- number of items in history (including the current one)
|
||||
function Defined(V: Variable) return Natural;
|
||||
|
||||
-- non-destructively search for old values
|
||||
function Peek(V: Variable; Generation: Natural := 1) return Item_Type;
|
||||
-- V.Peek(0) returns current value; V.Peek(1) the previous value, etc.
|
||||
-- when calling V.Peek(i), i must be in 0 .. V.Defined-1, else Constraint_Error is raised
|
||||
|
||||
-- destructively restore previous value
|
||||
procedure Undo(V: in out Variable);
|
||||
-- old V.Peek(0) is forgotten, old V.Peek(i) is new V.Peek(i-1), etc.
|
||||
-- accordingly, V.Defined decrements by 1
|
||||
-- special case: if V.Defined=0 then V.Undo does not change V
|
||||
|
||||
private
|
||||
package Vectors is new Ada.Containers.Indefinite_Vectors
|
||||
(Index_Type => Positive,
|
||||
Element_Type => Item_Type);
|
||||
|
||||
type Variable is tagged limited record
|
||||
History: Vectors.Vector;
|
||||
end record;
|
||||
end History_Variables;
|
||||
|
|
@ -1,35 +0,0 @@
|
|||
package body History_Variables is
|
||||
|
||||
-- set and get
|
||||
procedure Set(V: in out Variable; Item: Item_Type) is
|
||||
begin
|
||||
V.History.Prepend(Item);
|
||||
end Set;
|
||||
|
||||
function Get(V: Variable) return Item_Type is
|
||||
begin
|
||||
return V.History.First_Element;
|
||||
end Get;
|
||||
|
||||
-- number of items in history (including the current one)
|
||||
function Defined(V: Variable) return Natural is
|
||||
begin
|
||||
return (1 + V.History.Last_Index) - V.History.First_Index;
|
||||
end Defined;
|
||||
|
||||
-- non-destructively search
|
||||
function Peek(V: Variable; Generation: Natural := 1) return Item_Type is
|
||||
Index: Positive := V.History.First_Index + Generation;
|
||||
begin
|
||||
if Index > V.History.Last_Index then
|
||||
raise Constraint_Error;
|
||||
end if;
|
||||
return V.History.Element(Index);
|
||||
end Peek;
|
||||
|
||||
procedure Undo(V: in out Variable) is
|
||||
begin
|
||||
V.History.Delete_First;
|
||||
end Undo;
|
||||
|
||||
end History_Variables;
|
||||
|
|
@ -1,32 +0,0 @@
|
|||
with Ada.Text_IO, History_Variables;
|
||||
|
||||
procedure Test_History is
|
||||
|
||||
package Int_With_Hist is new History_Variables(Integer);
|
||||
|
||||
-- define a history variable
|
||||
I: Int_With_Hist.Variable;
|
||||
|
||||
Sum: Integer := 0;
|
||||
|
||||
begin
|
||||
|
||||
-- assign three values
|
||||
I.Set(3);
|
||||
I.Set(I.Get + 4);
|
||||
I.Set(9);
|
||||
|
||||
-- non-destructively display the history
|
||||
for N in reverse 0 .. I.Defined-1 loop
|
||||
Ada.Text_IO.Put(Integer'Image(I.Peek(N)));
|
||||
end loop;
|
||||
Ada.Text_IO.New_Line;
|
||||
|
||||
-- recall the three values
|
||||
while I.Defined > 0 loop
|
||||
Sum := Sum + I.Get;
|
||||
I.Undo;
|
||||
end loop;
|
||||
Ada.Text_IO.Put_Line(Integer'Image(Sum));
|
||||
|
||||
end Test_History;
|
||||
|
|
@ -1,32 +0,0 @@
|
|||
with Ada.Text_IO, History_Variables;
|
||||
|
||||
procedure Test_History is
|
||||
|
||||
package Str_With_Hist is new History_Variables(String);
|
||||
|
||||
-- define a history variable
|
||||
S: Str_With_Hist.Variable;
|
||||
|
||||
Sum: Integer := 0;
|
||||
|
||||
begin
|
||||
|
||||
-- assign three values
|
||||
S.Set("one");
|
||||
S.Set(S.Get & S.Get); --"oneone"
|
||||
S.Set("three");
|
||||
|
||||
-- non-destructively display the history
|
||||
for N in reverse 0 .. S.Defined-1 loop
|
||||
Ada.Text_IO.Put(S.Peek(Generation => N) &" ");
|
||||
end loop;
|
||||
Ada.Text_IO.New_Line;
|
||||
|
||||
-- recall the three values
|
||||
while S.Defined > 0 loop
|
||||
Sum := Sum + S.Get'Length;
|
||||
S.Undo;
|
||||
end loop;
|
||||
Ada.Text_IO.Put_Line(Integer'Image(Sum));
|
||||
|
||||
end Test_History;
|
||||
|
|
@ -1,45 +1,42 @@
|
|||
define :history [][
|
||||
init: [
|
||||
define :history [
|
||||
init: method [][
|
||||
this\record: @[0]
|
||||
]
|
||||
]
|
||||
assign: function [historyVar,newValue][
|
||||
historyVar\record: historyVar\record ++ newValue
|
||||
assign: method [newValue][
|
||||
this\record: this\record ++ newValue
|
||||
]
|
||||
|
||||
records: method [][
|
||||
this\record
|
||||
]
|
||||
|
||||
retrieve: method [][
|
||||
result: last this\record
|
||||
this\record: chop this\record
|
||||
return result
|
||||
]
|
||||
|
||||
current: method [][
|
||||
return last this\record
|
||||
]
|
||||
]
|
||||
|
||||
alias.infix {'-->} 'assign
|
||||
|
||||
records: function [historyVar][
|
||||
historyVar\record
|
||||
]
|
||||
|
||||
retrieve: function [historyVar][
|
||||
result: last historyVar\record
|
||||
historyVar\record: chop historyVar\record
|
||||
return result
|
||||
]
|
||||
|
||||
current: function [historyVar][
|
||||
return last historyVar\record
|
||||
]
|
||||
|
||||
do [
|
||||
h: to :history []
|
||||
h: to :history []
|
||||
|
||||
do ::
|
||||
print "Assigning three values: 1, 2, 3..."
|
||||
h --> 1
|
||||
h --> 2
|
||||
h --> 3
|
||||
h\assign 1
|
||||
h\assign 2
|
||||
h\assign 3
|
||||
|
||||
print "\nHistory (oldest values first):"
|
||||
print [">" records h]
|
||||
print [">" h\records]
|
||||
|
||||
print ["\nCurrent value is:" current h]
|
||||
print ["\nCurrent value is:" h\current]
|
||||
|
||||
print "\nRecalling the three values..."
|
||||
loop 1..3 'x ->
|
||||
print ["- Recalled:" retrieve h]
|
||||
print ["- Recalled:" h\retrieve]
|
||||
|
||||
print "\nHistory:"
|
||||
print [">" records h]
|
||||
]
|
||||
print [">" h\records]
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ class HistoryVariable
|
|||
|
||||
undo()
|
||||
{
|
||||
ifnot (previous.isEmpty())
|
||||
if:not (previous.isEmpty())
|
||||
{
|
||||
value := previous.pop()
|
||||
}
|
||||
|
|
@ -40,7 +40,7 @@ class HistoryVariable
|
|||
string toPrintable() => this value;
|
||||
}
|
||||
|
||||
public program()
|
||||
public Program()
|
||||
{
|
||||
var o := new HistoryVariable();
|
||||
o.Value := 5;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue