summaryrefslogtreecommitdiff
path: root/src/kompsos.adb
diff options
context:
space:
mode:
authorJedidiah Barber <contact@jedbarber.id.au>2025-11-16 21:35:17 +1300
committerJedidiah Barber <contact@jedbarber.id.au>2025-11-16 21:35:17 +1300
commitd0f8cc922207cd066a7a44aa3fa24fcd9158bbd0 (patch)
tree134cc05a85a41e2e83725311cc5efc461422854e /src/kompsos.adb
parent203222f4ffbdaf23a30ab390a7ad765cfef0c008 (diff)
Improvements to Fresh and Take
Diffstat (limited to 'src/kompsos.adb')
-rw-r--r--src/kompsos.adb67
1 files changed, 45 insertions, 22 deletions
diff --git a/src/kompsos.adb b/src/kompsos.adb
index b3816fa..f338e7e 100644
--- a/src/kompsos.adb
+++ b/src/kompsos.adb
@@ -84,7 +84,7 @@ package body Kompsos is
function Name
(This : in Term)
- return SU.Unbounded_String is
+ return Nametag is
begin
return This.Var.Name;
end Name;
@@ -464,7 +464,7 @@ package body Kompsos is
function Fresh
(This : in out World'Class;
- Name : in Ada.Strings.Unbounded.Unbounded_String)
+ Name : in Nametag)
return Term
is
My_ID : constant Generator_ID_Number := Next_Gen;
@@ -480,6 +480,30 @@ package body Kompsos is
end Fresh;
+ function Fresh
+ (This : in out World'Class;
+ Count : in Positive)
+ return Term_Array
+ is
+ Names : constant Nametag_Array (1 .. Count) := (others => +"");
+ begin
+ return This.Fresh (Names);
+ end Fresh;
+
+
+ function Fresh
+ (This : in out World'Class;
+ Names : in Nametag_Array)
+ return Term_Array is
+ begin
+ return Terms : Term_Array (1 .. Names'Length) do
+ for Index in Terms'Range loop
+ Terms (Index) := This.Fresh (Names (Names'First + Index - 1));
+ end loop;
+ end return;
+ end Fresh;
+
+
-- Unification --
@@ -685,31 +709,30 @@ package body Kompsos is
-- Forced Evaluation --
function Take
- (This : in World;
- Count : in Natural)
- return World is
- begin
- if Count = 0 then
- return
- (Possibles => State_Vectors.Empty_Vector,
- Engine => (Kind => No_Gen));
- end if;
- return Result : World := This do
- Result.Roll_Until (Count);
- if Result.Possibles.Last_Index > Count then
- Result.Possibles.Set_Length (Ada.Containers.Count_Type (Count));
- end if;
- Result.Engine := (Kind => No_Gen);
+ (This : in out World;
+ Count : in Positive)
+ return State_Array is
+ begin
+ This.Force (Count);
+ return Result : State_Array (1 .. Integer'Min (Count, This.Possibles.Last_Index)) do
+ for Index in Result'Range loop
+ Result (Index) := This.Possibles.Element (Index);
+ end loop;
end return;
end Take;
- procedure Take
- (This : in out World;
- Count : in Natural) is
+ function Take_First
+ (This : in out World)
+ return State is
begin
- This := This.Take (Count);
- end Take;
+ This.Force (1);
+ if This.Possibles.Is_Empty then
+ return Empty_State;
+ else
+ return This.Possibles.First_Element;
+ end if;
+ end Take_First;
procedure Force