Exemplo n.º 1
0
    def _eval_and(self, expr, env):
        if procedure.no_operands(procedure.operands(expr)):
            return Boolean(True)

        def inner(expr, env):
            if sequence.is_last_expr(expr):
                return self._eval(sequence.first_expr(expr), env)

            if not self._eval(sequence.first_expr(expr), env):
                return Boolean(False)

            return inner(sequence.rest_exprs(expr), env)

        return inner(sequence.rest_exprs(expr), env)
Exemplo n.º 2
0
    def _eval_or(self, expr, env):
        if procedure.no_operands(procedure.operands(expr)):
            return Boolean(False)

        def inner(expr, env):
            if sequence.is_last_expr(expr):
                return self._eval(sequence.first_expr(expr), env)

            first_value = self._eval(sequence.first_expr(expr), env)
            if first_value:
                return first_value

            return inner(sequence.rest_exprs(expr), env)

        return inner(sequence.rest_exprs(expr), env)
Exemplo n.º 3
0
    def _eval(self, expr, env):
        if selfeval.is_self_evaluating(expr):
            return expr

        if quote.is_quoted(expr):
            return quote.text_of_quotation(expr)

        if definition.is_definition(expr):
            return self._eval_definition(expr, env)

        if sequence.is_begin(expr):
            return self._eval_sequence(sequence.begin_actions(expr), env)

        if binding.is_let_binding(expr):
            return self._eval_binding(expr, env)

        if variable.is_variable(expr):
            return lookup_variable_value(expr, env)

        if assignment.is_assignment(expr):
            return self._eval_assignment(expr, env)

        if conditional.is_if(expr):
            return self._eval_if(expr, env)

        if conditional.is_cond(expr):
            return self._eval(conditional.cond_to_if(expr), env)

        if conditional.is_and(expr):
            return self._eval_and(expr, env)

        if conditional.is_or(expr):
            return self._eval_or(expr, env)

        if lambdaexpr.is_lambda(expr):
            return procedure.make_procedure(
                lambdaexpr.lambda_parameters(expr),
                lambdaexpr.lambda_body(expr),
                env
                )

        if procedure.is_application(expr):
            return self._apply(
                self._eval(procedure.operator(expr), env),
                self._list_of_values(procedure.operands(expr), env)
                )