Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
Add a setter in ClonableArray and ClonableList
Browse files Browse the repository at this point in the history
  • Loading branch information
patxikuku committed Apr 10, 2014
1 parent 37c8a8c commit 1052b86
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/sage/structure/list_clone.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ cdef class ClonableArray(ClonableElement):

cpdef list _get_list(self)
cpdef _set_list(self, list lst)
cpdef set_list(self, list lst)
cpdef ClonableArray __copy__(self)
cpdef check(self)
cpdef object _getitem(self, int key)
Expand Down
28 changes: 28 additions & 0 deletions src/sage/structure/list_clone.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,34 @@ cdef class ClonableArray(ClonableElement):
"""
self._list = lst

cpdef set_list(self, list lst):
"""
Set the list embedded in ``self``.
The list given in parameter is copied.
EXAMPLES::
sage: from sage.structure.list_clone_demo import IncreasingArrays
sage: el = IncreasingArrays()([1,2,3])
sage: l = [1,4,5]
sage: with el.clone() as el1 :
....: el1.set_list( l )
sage: el1
[1, 4, 5]
TESTS::
sage: from sage.structure.list_clone_demo import IncreasingArrays
sage: el = IncreasingArrays()([1,2,3])
sage: l = [1,4,5]
sage: with el.clone() as el1 :
....: el1.set_list( l )
sage: el1._get_list() is l
False
"""
self._require_mutable()
self._list = list(lst)

def __len__(self):
"""
Returns the len of ``self``
Expand Down

0 comments on commit 1052b86

Please sign in to comment.