From 6f947f3483171032ce9cfd51fec04f92b6d55ba6 Mon Sep 17 00:00:00 2001 From: A4-Tacks Date: Sat, 4 May 2024 16:56:48 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=B8=80=E4=B8=AA=E5=B0=8F?= =?UTF-8?q?=E7=9A=84match=E7=9B=B8=E5=85=B3=E5=B7=A5=E5=85=B7=E9=9B=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- examples/std/match_utils.mdtlbl | 45 +++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 examples/std/match_utils.mdtlbl diff --git a/examples/std/match_utils.mdtlbl b/examples/std/match_utils.mdtlbl new file mode 100644 index 0000000..80c1df6 --- /dev/null +++ b/examples/std/match_utils.mdtlbl @@ -0,0 +1,45 @@ +take MatchUtils = (); + +const MatchUtils.AssertEvalable = (inline@{ + #** + * 断言是否每个参数都能eval + *# + const match @ { + N { + match `Builtin`.EvalNum[N] { + [`__`] { + take Msg = `Builtin`.Concat[ + `Builtin`.Stringify[N]->$ + " is not evalable" + ]; + take `Builtin`.Err[Msg]; + take `Builtin`.ExpandStack[]; + take `Builtin`.Exit[3]; + setres `__`; + } + @ {} + } + } + } +}); +const MatchUtils.ForC = ([MU:MatchUtils](const match @ { + #** + * 静态的将给定值进行for操作 + *# + *Stop F { + take MU.ForC[0 Stop F]; + } + *Start *Stop F { + take MU.ForC[Start Stop 1 F]; + } + *Start *Stop *Step F { + MU.AssertEvalable[Start Stop Step]; + const Do = (const match @ { + I:[?_0 < Stop] { + take F[I]; + take Do[(?I+Step)->$]; + } + }); + take Do[Start]; +} +}));