From: Nicolas Boulenguez Date: Wed, 8 May 2019 01:07:45 +0000 (+0200) Subject: ada.2 switch back `do` from built-in function to special form X-Git-Url: https://git.hcoop.net/jackhill/mal.git/commitdiff_plain/c58f50e6bea148ab0ff06a8493ccf382d719ca23?hp=ef1de022d437ded9ba3eab9793f6b0143d62043d ada.2 switch back `do` from built-in function to special form The benefit of this devianceto the process is dubious. --- diff --git a/ada.2/core.adb b/ada.2/core.adb index 5c00bb55..d1539b42 100644 --- a/ada.2/core.adb +++ b/ada.2/core.adb @@ -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); diff --git a/ada.2/step4_if_fn_do.adb b/ada.2/step4_if_fn_do.adb index 6d26a79e..08ab35b8 100644 --- a/ada.2/step4_if_fn_do.adb +++ b/ada.2/step4_if_fn_do.adb @@ -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 diff --git a/ada.2/step5_tco.adb b/ada.2/step5_tco.adb index 5dbcc2a1..e3707253 100644 --- a/ada.2/step5_tco.adb +++ b/ada.2/step5_tco.adb @@ -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 diff --git a/ada.2/step6_file.adb b/ada.2/step6_file.adb index bd22cff8..5bab8772 100644 --- a/ada.2/step6_file.adb +++ b/ada.2/step6_file.adb @@ -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 diff --git a/ada.2/step7_quote.adb b/ada.2/step7_quote.adb index c3ccdfbe..7be50816 100644 --- a/ada.2/step7_quote.adb +++ b/ada.2/step7_quote.adb @@ -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 diff --git a/ada.2/step8_macros.adb b/ada.2/step8_macros.adb index a5726f0a..c0d2b995 100644 --- a/ada.2/step8_macros.adb +++ b/ada.2/step8_macros.adb @@ -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 diff --git a/ada.2/step9_try.adb b/ada.2/step9_try.adb index 6c910611..397f1db5 100644 --- a/ada.2/step9_try.adb +++ b/ada.2/step9_try.adb @@ -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 diff --git a/ada.2/stepa_mal.adb b/ada.2/stepa_mal.adb index b912336c..19035349 100644 --- a/ada.2/stepa_mal.adb +++ b/ada.2/stepa_mal.adb @@ -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