~jasper/type_stack_calc

d12742ff0c28f1241bf1abca88552039a949d87c — Jasper den Ouden 6 months ago 0660e1d
Infix code did not properly take into account the case of a string. Also made SimpleInbuildFunction make a bunch of function names(+-*/ etc) infix automatically
2 files changed, 8 insertions(+), 4 deletions(-)

M type_stack_calc/base/function.py
M type_stack_calc/ib/simple_ib_fun.py
M type_stack_calc/base/function.py => type_stack_calc/base/function.py +3 -3
@@ 59,17 59,17 @@ NOTE: does the real work of counting arguments."""
                s += '('  # Infix-separated arguments. (, for functions)

            if infix is True:  # Interpret `infix`.
                c_infix = " " + cname + " "
                infix = " " + cname + " "
            elif not isinstance(infix, str):
                assert infix is False
                c_infix = ", "
                infix = ", "

            if n > 0:  # The arguments come from the generator.
                c_outputs = listing_do_c_args(gen, n,
                                              self[1], cname or '(')
                # Need it reversed.
                c_outputs = reversed(list(c_outputs))
                s += c_infix.join(''.join(cl) for cl in c_outputs)
                s += infix.join(''.join(cl) for cl in c_outputs)

            if surround:
                s += ")"

M type_stack_calc/ib/simple_ib_fun.py => type_stack_calc/ib/simple_ib_fun.py +5 -1
@@ 46,6 46,8 @@ class IBVariant(tuple, BaseFunctionVariant):

from type_stack_calc.util.markings_in_stack import markings_in_stack
from type_stack_calc.util.stack_check import assert_acceptable_vals
# For infixing a bunch of names automatically.
from type_stack_calc.util.fun_info import infixed_set

# NOTE: with "more advanced" type compilation, i noticed might want to note
#  some of the results on the object instead of re-calculating.


@@ 53,9 55,11 @@ from type_stack_calc.util.stack_check import assert_acceptable_vals
class SimpleInbuildFunction(BaseFunction):
    """Relatively simple inbuild function."""

    def __init__(self, args, fun, name=None, infix=False, with_vars=False,
    def __init__(self, args, fun, name=None, infix=None, with_vars=False,
                 destructive=False, definitional=False, extract_n=None,
                 tp='method'):
        infix = (infix is None and name in infixed_set) or infix or False 

        BaseFunction.__init__(self, name, args, infix, with_vars,
                              destructive, definitional, tp)
        self.fun = fun