예제 #1
0
 def eval_and_exec_if_else(self, cmd, args):
     # If statements are a special case since we only want to execute the lambdas of the arguments based on the
     # predicate. Therefore only the first argument (the predicate) is evaluated at this stage, and the relevant
     # result is evaluated within the function itself
     args_eval = args.copy()  # Avoid modifying the original arguments
     args_eval[0] = args_eval[0]()
     if self.is_symbol(args_eval[0]):
         args_eval[0] = self.get_symbol_value(args_eval[0])
     return CommandsInspector.execute_command(self.commands, cmd, args_eval)
예제 #2
0
 def eval_and_exec_general(self, cmd, args):
     # First execute all lambda functions for all arguments, reducing them all to either numbers or symbols
     # Then resolve all symbols by replacing them with their defined values
     args_eval = args.copy()  # Avoid modifying the original arguments
     for idx, arg in enumerate(args_eval):
         args_eval[idx] = arg()
         if self.is_symbol(args_eval[idx]):
             args_eval[idx] = self.get_symbol_value(args_eval[idx])
     return CommandsInspector.execute_command(self.commands, cmd, args_eval)
예제 #3
0
 def eval_and_exec_define(self, cmd, args):
     # Define is a special case since it expects the first argument to be an undefined symbol, so we must not
     # attempt to fully resolve it
     args_eval = args.copy()  # Avoid modifying the original arguments
     for idx, arg in enumerate(args_eval):
         args_eval[idx] = arg()
     if self.is_symbol(args_eval[1]):
         args_eval[1] = self.get_symbol_value(args_eval[1])
     return CommandsInspector.execute_command(self.commands, cmd, args_eval)