def fill(obj, index = 0, length = nil)
      raise Erlang::ImproperListError if improper?
      obj = Erlang.from(obj)
      if index == 0
        length ||= size
        if length > 0
          out = tail = Erlang::Cons.allocate
          list = self
          while length > 0
            new_node = Erlang::Cons.allocate
            new_node.instance_variable_set(:@head, obj)
            new_node.instance_variable_set(:@improper, false)
            tail.instance_variable_set(:@tail, new_node)
            tail.instance_variable_set(:@improper, false)
            tail.immutable!
            tail = new_node
            list = list.tail
            length -= 1
          end
          if not tail.immutable?
            tail.instance_variable_set(:@tail, list)
            tail.immutable!
          end
          return out.tail
        else
          self
        end
      elsif index > 0
        length ||= size - index
        length = 0 if length < 0
        out = tail = Erlang::Cons.allocate
        list = self
        while index > 0
          new_node = Erlang::Cons.allocate
          new_node.instance_variable_set(:@head, list.head)
          new_node.instance_variable_set(:@improper, false)
          tail.instance_variable_set(:@tail, new_node)
          tail.instance_variable_set(:@improper, false)
          tail.immutable!
          tail = new_node
          list = list.tail
          index -= 1
        end
        while length > 0
          new_node = Erlang::Cons.allocate
          new_node.instance_variable_set(:@head, obj)
          new_node.instance_variable_set(:@improper, false)
          tail.instance_variable_set(:@tail, new_node)
          tail.instance_variable_set(:@improper, false)
          tail.immutable!
          tail = new_node
          list = list.tail
          length -= 1
        end
        if not tail.immutable?
          tail.instance_variable_set(:@tail, list)
          tail.immutable!
        end
        return out.tail
      else
        raise IndexError if index < -size
        return fill(obj, index + size, length)
      end
    end
def fill(obj, index = 0, length = nil)
      raise Erlang::ImproperListError if improper?
      obj = Erlang.from(obj)
      if index == 0
        length ||= size
        if length > 0
          out = tail = Erlang::Cons.allocate
          list = self
          while length > 0
            new_node = Erlang::Cons.allocate
            new_node.instance_variable_set(:@head, obj)
            new_node.instance_variable_set(:@improper, false)
            tail.instance_variable_set(:@tail, new_node)
            tail.instance_variable_set(:@improper, false)
            tail.immutable!
            tail = new_node
            list = list.tail
            length -= 1
          end
          if not tail.immutable?
            tail.instance_variable_set(:@tail, list)
            tail.immutable!
          end
          return out.tail
        else
          self
        end
      elsif index > 0
        length ||= size - index
        length = 0 if length < 0
        out = tail = Erlang::Cons.allocate
        list = self
        while index > 0
          new_node = Erlang::Cons.allocate
          new_node.instance_variable_set(:@head, list.head)
          new_node.instance_variable_set(:@improper, false)
          tail.instance_variable_set(:@tail, new_node)
          tail.instance_variable_set(:@improper, false)
          tail.immutable!
          tail = new_node
          list = list.tail
          index -= 1
        end
        while length > 0
          new_node = Erlang::Cons.allocate
          new_node.instance_variable_set(:@head, obj)
          new_node.instance_variable_set(:@improper, false)
          tail.instance_variable_set(:@tail, new_node)
          tail.instance_variable_set(:@improper, false)
          tail.immutable!
          tail = new_node
          list = list.tail
          length -= 1
        end
        if not tail.immutable?
          tail.instance_variable_set(:@tail, list)
          tail.immutable!
        end
        return out.tail
      else
        raise IndexError if index < -size
        return fill(obj, index + size, length)
      end
    end
Replace a range of indexes with the given object.

 @overload fill(object)
   Return a new `List` of the same size, with every index set to `object`.

   @param [Object] object Fill value.
   @example
     Erlang::List["A", "B", "C", "D", "E", "F"].fill("Z")
     # => Erlang::List["Z", "Z", "Z", "Z", "Z", "Z"]

 @overload fill(object, index)
   Return a new `List` with all indexes from `index` to the end of the
   vector set to `obj`.

   @param [Object] object Fill value.
   @param [Integer] index Starting index. May be negative.
   @example
     Erlang::List["A", "B", "C", "D", "E", "F"].fill("Z", 3)
     # => Erlang::List["A", "B", "C", "Z", "Z", "Z"]

 @overload fill(object, index, length)
   Return a new `List` with `length` indexes, beginning from `index`,
   set to `obj`. Expands the `List` if `length` would extend beyond the
   current length.

   @param [Object] object Fill value.
   @param [Integer] index Starting index. May be negative.
   @param [Integer] length
   @example
     Erlang::List["A", "B", "C", "D", "E", "F"].fill("Z", 3, 2)
     # => Erlang::List["A", "B", "C", "Z", "Z", "F"]
     Erlang::List["A", "B"].fill("Z", 1, 5)
     # => Erlang::List["A", "Z", "Z", "Z", "Z", "Z"]

 @return [List]
 @raise [IndexError] if index is out of negative range.