コード例 #1
0
ファイル: Builtin.cs プロジェクト: wj32/Lambda
 public Expression CreatePair(BuiltinPair pair)
 {
     return new FreeSymbolExpression { Name = "_Pair", Tag = pair, Display = _PairDisplay };
 }
コード例 #2
0
ファイル: Evaluator.cs プロジェクト: wj32/Lambda
        public static bool RecognizePair(Expression expression, out BuiltinPair value)
        {
            // \f.f <FIRST> <SECOND> is Pair

            value = null;

            if (expression is AbstractionExpression)
            {
                var abs = (AbstractionExpression)expression;

                if (abs.Right is ApplicationExpression)
                {
                    var app1 = (ApplicationExpression)abs.Right;

                    if (app1.Left is ApplicationExpression)
                    {
                        var app2 = (ApplicationExpression)app1.Left;

                        if (app2.Left is BoundSymbolExpression)
                        {
                            var bound = (BoundSymbolExpression)app2.Left;

                            if (bound.Symbol == abs.Left)
                            {
                                // Pair

                                value = new BuiltinPair { First = app2.Right, Second = app1.Right };
                                return true;
                            }
                        }
                    }
                }
            }

            return false;
        }