Beispiel #1
0
    def to_cons(cls, object_, result_type):
        """Converts object_ to Cons.
        """
        # Checks a length of sequence.
        if isinstance(object_, Null):
            sequence_length = 0
        else:
            sequence_length = len(object_.value)

        # If sequence_length is zero, SIMPLE-TYPE-ERROR is occured.
        if sequence_length == 0:
            raise SimpleTypeError("The requested length ({}) does not match the specified type {}.".format(
                str(sequence_length),
                str(result_type)
            ))

        if isinstance(object_.value, list):
            return Cons.tocons(object_.value)
        else: # If object_.value is not list, it is converted to list in advance.
            return Cons.tocons(list(object_.value))
Beispiel #2
0
    def eval_forms(cls, forms, var_env, func_env, macro_env):
        """Evaluates forms before these are given to functions as arguments.

        Returns:
            Cons.
        """
        from clispy.evaluator import Evaluator

        args = []
        while forms is not Null():
            args.append(Evaluator.eval(forms.car, var_env, func_env, macro_env))
            forms = forms.cdr

        return Cons.tocons(args)