コード例 #1
0
        public static LispRuntimeFunction GetLambda(Context lambdaContext, Lambda lambda, string name)
        {
            LispFunction function = (Context context, LispLiteral[] args) =>
            {
                var evaluatedArgs = EvalArgs(context, args.ToList());
                if (lambda.Parameters.Count > evaluatedArgs.Count)
                {
                    throw new Exception("ouch : not enough arguments for lambda " + lambda);
                }

                var scope = new Dictionary <string, LispLiteral>();
                int i     = 0;
                foreach (SymbolLiteral parameter in lambda.Parameters)
                {
                    scope[parameter.Value] = evaluatedArgs[i];
                    i++;
                }

                var scopedContext = new Context(scope, context);
                var result        = LispInterpreter.Interprete(scopedContext, lambda.Body);

                return(result);
            };
            var lfunction = new LispRuntimeFunction(function);

            lfunction.IsLambda = true;
            return(lfunction);
        }
コード例 #2
0
 public static LispLiteral EvalArg(Context context, LispLiteral arg)
 {
     return(LispInterpreter.Interprete(context, arg));
 }