class ParameterList(list):
    """List of parameter values.
    
    Unlike lists, additions, subtractions, multiplications and divisions
    work element-wise.
    
    Can add, etc... strings corresponding to simulation parameters that
    were defined via default_value or with run's param or sweep arguments.
    """
    def __init__(self, items, sim):
        list.__init__(self, items)
        self._sim = sim
    
    def __add__(first, second):
        second = first._sim.value(second)
        if type(second) in (int, long, float):
            return ParameterList([x + second for x in first], first._sim)
        else:
            return ParameterList(list.__add__(first, second), first._sim)

    def __mul__(first, second):
        second = first._sim.value(second)
        if type(second) in (int, long, float):
            return ParameterList([x * second for x in first], first._sim)
        else:
            return ParameterList(list.__mul__(first, second), first._sim)

    def __div__(first, second):
        second = first._sim.value(second)
        if type(second) in (int, long, float):
            return ParameterList([x / second for x in first], first._sim)
        else:
            return ParameterList(list.__div__(first, second), first._sim)

    def __sub__(first, second):
        second = first._sim.value(second)
        if type(second) in (int, long, float):
            return ParameterList([x - second for x in first], first._sim)
        else:
            return ParameterList(list.__sub__(first, second), first._sim)

    def __iadd__(self, second):
        second = self._sim.value(second)
        if type(second) in (int, long, float):
            for i in range(len(self)):
                self[i] += second
        else:
            list.__iadd__(self, second)
        return self

    def __imul__(self, second):
        second = self._sim.value(second)
        if type(second) in (int, long, float):
            for i in range(len(self)):
                self[i] *= second
        else:
            list.__imul__(self, second)
        return self

    def __idiv__(self, second):
        second = self._sim.value(second)
        if type(second) in (int, long, float):
            for i in range(len(self)):
                self[i] /= second
        else:
            list.__idiv__(self, second)
        return self

