@@ -26,6 +26,8 @@ def reduce_small(self, f, init):
2626 init = f .invoke ([init , self ._list [x ]])
2727 return init
2828
29+ def list (self ):
30+ return self ._list
2931
3032 def reduce_large (self , f , init ):
3133 for x in range (len (self ._list )):
@@ -37,30 +39,30 @@ def reduce_large(self, f, init):
3739@extend (proto ._count , Array )
3840def _count (self ):
3941 assert isinstance (self , Array )
40- return rt .wrap (len (self ._list ))
42+ return rt .wrap (len (self .list () ))
4143
4244@extend (proto ._nth , Array )
4345def _nth (self , idx ):
4446 assert isinstance (self , Array )
4547 ival = idx .int_val ()
46- if ival < len (self ._list ):
47- return self ._list [ival ]
48+ if ival < len (self .list () ):
49+ return self .list () [ival ]
4850 else :
4951 affirm (False , u"Index out of Range" )
5052
5153@extend (proto ._nth_not_found , Array )
5254def _nth_not_found (self , idx , not_found ):
5355 assert isinstance (self , Array )
5456 ival = idx .int_val ()
55- if ival < len (self ._list ):
56- return self ._list [ival ]
57+ if ival < len (self .list () ):
58+ return self .list () [ival ]
5759 else :
5860 return not_found
5961
6062@extend (proto ._reduce , Array )
6163def reduce (self , f , init ):
6264 assert isinstance (self , Array )
63- if len (self ._list ) > UNROLL_IF_SMALLER_THAN :
65+ if len (self .list () ) > UNROLL_IF_SMALLER_THAN :
6466 return self .reduce_large (f , init )
6567 return self .reduce_small (f , init )
6668
@@ -122,34 +124,39 @@ def array(lst):
122124
123125@as_var ("aget" )
124126def aget (self , idx ):
125- assert isinstance (self , Array )
126- return self ._list [idx .int_val ()]
127+ affirm (isinstance (self , Array ), u"aget expects an Array as the first argument" )
128+ affirm (isinstance (idx , Integer ), u"aget expects an Integer as the second argument" )
129+ return self .list ()[idx .int_val ()]
127130
128131@as_var ("aset" )
129132def aset (self , idx , val ):
130- assert isinstance (self , Array )
131- self ._list [idx .int_val ()] = val
133+ affirm (isinstance (self , Array ), u"aset expects an Array as the first argument" )
134+ affirm (isinstance (idx , Integer ), u"aset expects an Integer as the second argument" )
135+ self .list ()[idx .int_val ()] = val
132136 return val
133137
134138@as_var ("aslice" )
135139def aslice (self , offset ):
136- assert isinstance (self , Array ) and isinstance (offset , Integer )
140+ affirm (isinstance (self , Array ), u"aset expects an Array as the first argument" )
141+ affirm (isinstance (offset , Integer ), u"aset expects an Integer as the second argument" )
137142
138143 offset = offset .int_val ()
139144 if offset >= 0 :
140- return Array (self ._list [offset :])
145+ return Array (self .list () [offset :])
141146 else :
142147 rt .throw (rt .wrap (u"offset must be an Integer >= 0" ))
143148
144149@as_var ("aconcat" )
145150def aconcat (self , other ):
146- assert isinstance (self , Array ) and isinstance (other , Array )
147- return Array (self ._list + other ._list )
151+ affirm (isinstance (self , Array ) and isinstance (other , Array ),
152+ u"aconcat expects 2 Arrays" )
153+ return Array (self .list () + other .list ())
148154
149155@as_var ("alength" )
150156def alength (self ):
151- assert isinstance (self , Array )
152- return rt .wrap (len (self ._list ))
157+ affirm (isinstance (self , Array ), u"alength expects an Array" )
158+
159+ return rt .wrap (len (self .list ()))
153160
154161@as_var ("make-array" )
155162def make_array (l ):
0 commit comments