Example #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);
        }
Example #2
0
        public static LispLiteral Call(LispRuntimeFunction runtimeFunction, SExpr sexpr,
                                       Context context)
        {
            var args = sexpr.Tail;

            var result = runtimeFunction.Apply(context, args.ToArray());

            return(result);
        }