エレファント・ビジュアライザー調査記録

ビジュアルプログラミングで数式の変形を表すことを考えていくブロクです。

ラムダ計算と無限ラムダ多項式(3)

以下は Calc クラスの RepeatGenerator をラムダ式のようなもので書き直したもののイメージです。まだ動作するものではありません。C# で書いてもエラーにはならない形式になっています。単純な式のときは文字列で書けるようになっています。

        public static Func<string> RepeatGenerator = () =>
            new ExpBlock {
                Exp.Let("nums", Exp.List(Exp.Number(0), Exp.Number(3), Exp.Number(0))),
                Exp.Let("generator", Exp.Func("GenerateDecimal", new ExpList{})),
                Exp.Define("GetNextDecimalDigit", new NameList{}, new ExpBlock{
                    Exp.From("next(generator)"),
                    Exp.From("getCurrent(generator)"),
                }),
                Exp.Define("repeat", new NameList{"number","e","count" }, new ExpBlock{
                    Exp.If(Exp.From("e < count"),
                        Exp.From("repeat(number + lshift(GetNextDecimalDigit(), -e), e + 1, count)"),
                        Exp.From("number"))
                }),
                Exp.Let("result_number", Exp.From("repeat(0, 0, count)")),
                Exp.From("Print(result_number)")
            }.Eval(null).ToString();