Skip to content

Commit

Permalink
添加一个小的match相关工具集
Browse files Browse the repository at this point in the history
  • Loading branch information
A4-Tacks committed May 4, 2024
1 parent e30ec92 commit 6f947f3
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions examples/std/match_utils.mdtlbl
Original file line number Diff line number Diff line change
@@ -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];
}
}));

0 comments on commit 6f947f3

Please sign in to comment.