ada.2 switch back `do` from built-in function to special form
authorNicolas Boulenguez <nicolas.boulenguez@free.fr>
Wed, 8 May 2019 01:07:45 +0000 (03:07 +0200)
committerNicolas Boulenguez <nicolas.boulenguez@free.fr>
Wed, 8 May 2019 01:13:47 +0000 (03:13 +0200)
The benefit of this devianceto the process is dubious.

ada.2/core.adb
ada.2/step4_if_fn_do.adb
ada.2/step5_tco.adb
ada.2/step6_file.adb
ada.2/step7_quote.adb
ada.2/step8_macros.adb
ada.2/step9_try.adb
ada.2/stepa_mal.adb

index 5c00bb5..d1539b4 100644 (file)
@@ -79,7 +79,6 @@ package body Core is
    function Keyword       (Args : in Types.T_Array) return Types.T;
    function Less_Equal    is new Generic_Comparison ("<=");
    function Less_Than     is new Generic_Comparison ("<");
-   function Mal_Do        (Args : in Types.T_Array) return Types.T;
    function Meta          (Args : in Types.T_Array) return Types.T;
    function Pr_Str        (Args : in Types.T_Array) return Types.T;
    function Println       (Args : in Types.T_Array) return Types.T;
@@ -162,12 +161,6 @@ package body Core is
       return (Kind_Keyword, Args (Args'First).Str);
    end Keyword;
 
-   function Mal_Do (Args : in Types.T_Array) return Types.T is
-   begin
-      Err.Check (0 < Args'Length, "expected at least 1 parameter");
-      return Args (Args'Last);
-   end Mal_Do;
-
    function Meta (Args : in Types.T_Array) return Types.T is
    begin
       Err.Check (Args'Length = 1, "expected 1 parameter");
@@ -214,7 +207,6 @@ package body Core is
       P ("deref",       Types.Atoms.Deref'Access);
       P ("dissoc",      Types.Maps.Dissoc'Access);
       P ("/",           Division'Access);
-      P ("do",          Mal_Do'Access);
       P ("=",           Equals'Access);
       P ("first",       Types.Sequences.First'Access);
       P ("get",         Types.Maps.Get'Access);
index 6d26a79..08ab35b 100644 (file)
@@ -118,7 +118,16 @@ procedure Step4_If_Fn_Do is
                Env.all.Set (Key, Val); --  Check key kind.
                return Val;
             end;
-         --  do is a built-in function, shortening this test cascade.
+         elsif First.Str.all = "do" then
+            Err.Check (1 < Ast.Sequence.all.Length, "do expects arguments");
+            declare
+               Result : Types.T;
+            begin
+               for I in 2 .. Ast.Sequence.all.Length loop
+                  Result := Eval (Ast.Sequence.all.Data (I), Env);
+               end loop;
+               return Result;
+            end;
          elsif First.Str.all = "fn*" then
             Err.Check (Ast.Sequence.all.Length = 3, "expected 2 parameters");
             declare
index 5dbcc2a..e370725 100644 (file)
@@ -133,7 +133,16 @@ procedure Step5_Tco is
                Env.all.Set (Key, Val); --  Check key kind.
                return Val;
             end;
-         --  do is a built-in function, shortening this test cascade.
+         elsif First.Str.all = "do" then
+            Err.Check (1 < Ast.Sequence.all.Length, "do expects arguments");
+            declare
+               Result : Types.T;
+            begin
+               for I in 2 .. Ast.Sequence.all.Length loop
+                  Result := Eval (Ast.Sequence.all.Data (I), Env);
+               end loop;
+               return Result;
+            end;
          elsif First.Str.all = "fn*" then
             Err.Check (Ast.Sequence.all.Length = 3, "expected 2 parameters");
             declare
index bd22cff..5bab877 100644 (file)
@@ -137,7 +137,16 @@ procedure Step6_File is
                Env.all.Set (Key, Val); --  Check key kind.
                return Val;
             end;
-         --  do is a built-in function, shortening this test cascade.
+         elsif First.Str.all = "do" then
+            Err.Check (1 < Ast.Sequence.all.Length, "do expects arguments");
+            declare
+               Result : Types.T;
+            begin
+               for I in 2 .. Ast.Sequence.all.Length loop
+                  Result := Eval (Ast.Sequence.all.Data (I), Env);
+               end loop;
+               return Result;
+            end;
          elsif First.Str.all = "fn*" then
             Err.Check (Ast.Sequence.all.Length = 3, "expected 2 parameters");
             declare
index c3ccdfb..7be5081 100644 (file)
@@ -149,7 +149,16 @@ procedure Step7_Quote is
                Env.all.Set (Key, Val); --  Check key kind.
                return Val;
             end;
-         --  do is a built-in function, shortening this test cascade.
+         elsif First.Str.all = "do" then
+            Err.Check (1 < Ast.Sequence.all.Length, "do expects arguments");
+            declare
+               Result : Types.T;
+            begin
+               for I in 2 .. Ast.Sequence.all.Length loop
+                  Result := Eval (Ast.Sequence.all.Data (I), Env);
+               end loop;
+               return Result;
+            end;
          elsif First.Str.all = "fn*" then
             Err.Check (Ast.Sequence.all.Length = 3, "expected 2 parameters");
             declare
index a5726f0..c0d2b99 100644 (file)
@@ -163,7 +163,16 @@ procedure Step8_Macros is
                Env.all.Set (Key, Val);  --  Check key kind.
                return Val;
             end;
-         --  do is a built-in function, shortening this test cascade.
+         elsif First.Str.all = "do" then
+            Err.Check (1 < Ast.Sequence.all.Length, "do expects arguments");
+            declare
+               Result : Types.T;
+            begin
+               for I in 2 .. Ast.Sequence.all.Length loop
+                  Result := Eval (Ast.Sequence.all.Data (I), Env);
+               end loop;
+               return Result;
+            end;
          elsif First.Str.all = "fn*" then
             Err.Check (Ast.Sequence.all.Length = 3, "expected 2 parameters");
             declare
index 6c91061..397f1db 100644 (file)
@@ -163,7 +163,16 @@ procedure Step9_Try is
                Env.all.Set (Key, Val);  --  Check key kind.
                return Val;
             end;
-         --  do is a built-in function, shortening this test cascade.
+         elsif First.Str.all = "do" then
+            Err.Check (1 < Ast.Sequence.all.Length, "do expects arguments");
+            declare
+               Result : Types.T;
+            begin
+               for I in 2 .. Ast.Sequence.all.Length loop
+                  Result := Eval (Ast.Sequence.all.Data (I), Env);
+               end loop;
+               return Result;
+            end;
          elsif First.Str.all = "fn*" then
             Err.Check (Ast.Sequence.all.Length = 3, "expected 2 parameters");
             declare
index b912336..1903534 100644 (file)
@@ -164,7 +164,16 @@ procedure StepA_Mal is
                Env.all.Set (Key, Val);  --  Check key kind.
                return Val;
             end;
-         --  do is a built-in function, shortening this test cascade.
+         elsif First.Str.all = "do" then
+            Err.Check (1 < Ast.Sequence.all.Length, "do expects arguments");
+            declare
+               Result : Types.T;
+            begin
+               for I in 2 .. Ast.Sequence.all.Length loop
+                  Result := Eval (Ast.Sequence.all.Data (I), Env);
+               end loop;
+               return Result;
+            end;
          elsif First.Str.all = "fn*" then
             Err.Check (Ast.Sequence.all.Length = 3, "expected 2 parameters");
             declare