@@ -30,7 +30,7 @@ impl ToValue for StrFn {
3030 }
3131}
3232impl IFn for StrFn {
33- fn invoke ( & self , args : Vec < & Value > ) -> Value {
33+ fn invoke ( & self , args : Vec < Rc < Value > > ) -> Value {
3434 Value :: String (
3535 args. into_iter ( )
3636 . map ( |arg| arg. to_string ( ) )
@@ -48,7 +48,7 @@ impl ToValue for StringPrintFn {
4848 }
4949}
5050impl IFn for StringPrintFn {
51- fn invoke ( & self , args : Vec < & Value > ) -> Value {
51+ fn invoke ( & self , args : Vec < Rc < Value > > ) -> Value {
5252 Value :: String (
5353 args. into_iter ( )
5454 . map ( |arg| arg. to_string ( ) )
@@ -66,9 +66,9 @@ impl ToValue for AddFn {
6666 }
6767}
6868impl IFn for AddFn {
69- fn invoke ( & self , args : Vec < & Value > ) -> Value {
69+ fn invoke ( & self , args : Vec < Rc < Value > > ) -> Value {
7070 args. into_iter ( ) . fold ( 0_i32 . to_value ( ) , |a, b| match a {
71- Value :: I32 ( a_) => match b {
71+ Value :: I32 ( a_) => match * b {
7272 Value :: I32 ( b_) => Value :: I32 ( a_ + b_) ,
7373 _ => Value :: Condition ( format ! (
7474 "Type mismatch; Expecting: (i32 | i64 | f32 | f64), Found: {}" ,
@@ -100,7 +100,7 @@ impl ToValue for EvalFn {
100100 }
101101}
102102impl IFn for EvalFn {
103- fn invoke ( & self , args : Vec < & Value > ) -> Value {
103+ fn invoke ( & self , args : Vec < Rc < Value > > ) -> Value {
104104 // @TODO generalize arity exceptions, and other exceptions
105105 if args. len ( ) != 1 {
106106 return Value :: Condition ( format ! (
@@ -122,12 +122,12 @@ impl ToValue for DoFn {
122122 }
123123}
124124impl IFn for DoFn {
125- fn invoke ( & self , args : Vec < & Value > ) -> Value {
125+ fn invoke ( & self , args : Vec < Rc < Value > > ) -> Value {
126126 // @TODO generalize arity exceptions, and other exceptions
127127 if args. is_empty ( ) {
128128 return Value :: Nil ;
129129 }
130- ( * args. last ( ) . unwrap ( ) ) . clone ( )
130+ ( * * args. last ( ) . unwrap ( ) ) . clone ( )
131131 }
132132}
133133
@@ -145,7 +145,7 @@ impl ToValue for DoMacro {
145145 }
146146}
147147impl IFn for DoMacro {
148- fn invoke ( & self , args : Vec < & Value > ) -> Value {
148+ fn invoke ( & self , args : Vec < Rc < Value > > ) -> Value {
149149 // @TODO generalize arity exceptions, and other exceptions
150150 if args. is_empty ( ) {
151151 return vec ! [ Symbol :: intern( "do" ) . to_rc_value( ) , Rc :: new( Value :: Nil ) ]
@@ -173,7 +173,7 @@ impl ToValue for NthFn {
173173 }
174174}
175175impl IFn for NthFn {
176- fn invoke ( & self , args : Vec < & Value > ) -> Value {
176+ fn invoke ( & self , args : Vec < Rc < Value > > ) -> Value {
177177 // @TODO generalize arity exceptions, and other exceptions
178178 if args. len ( ) != 2 {
179179 return Value :: Condition ( format ! (
@@ -183,13 +183,13 @@ impl IFn for NthFn {
183183 }
184184 // @TODO change iteration to work with Value references, or even change invoke to work on Rc<..>
185185 // as we do everything else; surely we don't want to clone just to read from a collection
186- if let Some ( Value :: I32 ( ind) ) = args. get ( 1 ) {
187- if * ind < 0 {
186+ if let Value :: I32 ( ind) = * * args. get ( 1 ) . unwrap ( ) {
187+ if ind < 0 {
188188 return Value :: Condition ( format ! ( "Index cannot be negative; Index ({})" , ind) ) ;
189189 }
190- let ind = * ind as usize ;
190+ let ind = ind as usize ;
191191
192- match args. get ( 0 ) . unwrap ( ) {
192+ match & * * args. get ( 0 ) . unwrap ( ) {
193193 Value :: PersistentList ( Cons ( head, tail, count) ) => {
194194 let count = * count as usize ;
195195 if ind >= count {
@@ -240,9 +240,9 @@ impl ToValue for ConcatFn {
240240 }
241241}
242242impl IFn for ConcatFn {
243- fn invoke ( & self , args : Vec < & Value > ) -> Value {
244- let concatted_vec = args. iter ( ) . fold ( vec ! [ ] , |mut sum, coll| {
245- let coll_vec = match coll {
243+ fn invoke ( & self , args : Vec < Rc < Value > > ) -> Value {
244+ let concatted_vec = args. iter ( ) . fold ( Vec :: new ( ) , |mut sum, coll| {
245+ let coll_vec = match & * * coll {
246246 Value :: PersistentList ( plist) => {
247247 Rc :: new ( plist. clone ( ) ) . iter ( ) . collect :: < Vec < Rc < Value > > > ( )
248248 }
@@ -269,7 +269,7 @@ impl ToValue for PrintStringFn {
269269 }
270270}
271271impl IFn for PrintStringFn {
272- fn invoke ( & self , args : Vec < & Value > ) -> Value {
272+ fn invoke ( & self , args : Vec < Rc < Value > > ) -> Value {
273273 if args. len ( ) != 1 {
274274 return Value :: Condition ( format ! (
275275 "Wrong number of arguments given to function (Given: {}, Expected: {})" ,
@@ -291,7 +291,7 @@ impl ToValue for AssocFn {
291291 }
292292}
293293impl IFn for AssocFn {
294- fn invoke ( & self , args : Vec < & Value > ) -> Value {
294+ fn invoke ( & self , args : Vec < Rc < Value > > ) -> Value {
295295 // We don't want even args, because assoc works like
296296 // (assoc {} :a 1) ;; 3 args
297297 // (assoc {} :a 1 :b 2) ;; 5 args
@@ -303,12 +303,12 @@ impl IFn for AssocFn {
303303 ) ) ;
304304 }
305305
306- if let Value :: PersistentListMap ( pmap) = args. get ( 0 ) . unwrap ( ) {
306+ if let Value :: PersistentListMap ( pmap) = & * ( args. get ( 0 ) . unwrap ( ) . clone ( ) ) {
307307 let mut retval = pmap. clone ( ) ;
308308 for ( key_value, val_value) in args. into_iter ( ) . skip ( 1 ) . tuples ( ) {
309309 let key = key_value. to_rc_value ( ) ;
310310 let val = val_value. to_rc_value ( ) ;
311- println ! ( "key: {:?}, val: {:?}" , key, val) ;
311+ println ! ( "key: {:?}, val: {:?}" , key, val) ;
312312 retval = pmap. assoc ( key, val) ;
313313 }
314314 return Value :: PersistentListMap ( retval) ;
0 commit comments