Exemple #1
0
 private static JymlAST.Cons Apply(string proc, JymlAST.Cons arguments, JymlEnvironment env)
 {
     if (PrimitiveProcedure.PrimitiveProcedures.Keys.Contains(proc))
     {
         // (apply-primitive-procedure procedure arguments)
         return(new JymlAST.Cons(PrimitiveProcedure.PrimitiveProcedures[proc].Invoke(arguments.ParametersToArguments(env))));
     }
     else
     {
         /*
          * (eval-sequence (procedure-body procedure) (extend-enviroment
          *                                      (procedure-parameters procedure)
          *                                      arguments
          *                                      (procedure-enviroment procedure)))
          */
         Procedures p         = env.FrameNode[proc].Value as Procedures;
         string[]   variables = p.Parameters.ToArray <string>();
         JymlType[] values    = arguments.ParametersToArguments(env);
         //return EvalSequence(
         //    cons: (JymlAST.Cons)proc,
         //    env: p.Environment.ExtendEnvironment(variables, values)
         //);
         return(Eval(p.Body, p.Environment.ExtendEnvironment(variables, values)));
     }
 }
Exemple #2
0
 /*
  * (define (apply procedure arguments)
  *      (cond   [(primitive-procedure? procedure)
  *              (apply-primitive-procedure procedure arguments)]
  *              [(compound-procedure? procedure)
  *              (eval-sequence (procedure-body procedure) (extend-enviroment
  *                                                          (procedure-parameters procedure)
  *                                                          arguments
  *                                                          (procedure-enviroment procedure)))]
  *              [else (error "Unknown procedure type -- Apply" procedure)]))
  */
 private static JymlAST.Cons Apply(JymlAST.Cons proc, JymlAST.Cons arguments, JymlEnvironment env)
 {
     if (proc.car is string procedureName)
     {
         if (PrimitiveProcedure.PrimitiveProcedures.Keys.Contains(procedureName))
         {
             // (apply-primitive-procedure procedure arguments)
             return(new JymlAST.Cons(PrimitiveProcedure.PrimitiveProcedures[procedureName].Invoke(arguments.ParametersToArguments(env))));
         }
         else
         {
             /*
              * (eval-sequence (procedure-body procedure) (extend-enviroment
              *                                      (procedure-parameters procedure)
              *                                      arguments
              *                                      (procedure-enviroment procedure)))
              */
             Procedures p         = proc.car as Procedures;
             string[]   variables = p.Parameters.ToArray <string>();
             JymlType[] values    = arguments.ParametersToArguments(env);
             return(EvalSequence(
                        cons: proc,
                        env: p.Environment.ExtendEnvironment(variables, values)
                        ));
         }
     }
     else
     {
         throw new Exception();
     }
 }