@@ -30,7 +30,7 @@ impl ToValue for StrFn {
30
30
}
31
31
}
32
32
impl IFn for StrFn {
33
- fn invoke ( & self , args : Vec < & Value > ) -> Value {
33
+ fn invoke ( & self , args : Vec < Rc < Value > > ) -> Value {
34
34
Value :: String (
35
35
args. into_iter ( )
36
36
. map ( |arg| arg. to_string ( ) )
@@ -48,7 +48,7 @@ impl ToValue for StringPrintFn {
48
48
}
49
49
}
50
50
impl IFn for StringPrintFn {
51
- fn invoke ( & self , args : Vec < & Value > ) -> Value {
51
+ fn invoke ( & self , args : Vec < Rc < Value > > ) -> Value {
52
52
Value :: String (
53
53
args. into_iter ( )
54
54
. map ( |arg| arg. to_string ( ) )
@@ -66,9 +66,9 @@ impl ToValue for AddFn {
66
66
}
67
67
}
68
68
impl IFn for AddFn {
69
- fn invoke ( & self , args : Vec < & Value > ) -> Value {
69
+ fn invoke ( & self , args : Vec < Rc < Value > > ) -> Value {
70
70
args. into_iter ( ) . fold ( 0_i32 . to_value ( ) , |a, b| match a {
71
- Value :: I32 ( a_) => match b {
71
+ Value :: I32 ( a_) => match * b {
72
72
Value :: I32 ( b_) => Value :: I32 ( a_ + b_) ,
73
73
_ => Value :: Condition ( format ! (
74
74
"Type mismatch; Expecting: (i32 | i64 | f32 | f64), Found: {}" ,
@@ -100,7 +100,7 @@ impl ToValue for EvalFn {
100
100
}
101
101
}
102
102
impl IFn for EvalFn {
103
- fn invoke ( & self , args : Vec < & Value > ) -> Value {
103
+ fn invoke ( & self , args : Vec < Rc < Value > > ) -> Value {
104
104
// @TODO generalize arity exceptions, and other exceptions
105
105
if args. len ( ) != 1 {
106
106
return Value :: Condition ( format ! (
@@ -122,12 +122,12 @@ impl ToValue for DoFn {
122
122
}
123
123
}
124
124
impl IFn for DoFn {
125
- fn invoke ( & self , args : Vec < & Value > ) -> Value {
125
+ fn invoke ( & self , args : Vec < Rc < Value > > ) -> Value {
126
126
// @TODO generalize arity exceptions, and other exceptions
127
127
if args. is_empty ( ) {
128
128
return Value :: Nil ;
129
129
}
130
- ( * args. last ( ) . unwrap ( ) ) . clone ( )
130
+ ( * * args. last ( ) . unwrap ( ) ) . clone ( )
131
131
}
132
132
}
133
133
@@ -145,7 +145,7 @@ impl ToValue for DoMacro {
145
145
}
146
146
}
147
147
impl IFn for DoMacro {
148
- fn invoke ( & self , args : Vec < & Value > ) -> Value {
148
+ fn invoke ( & self , args : Vec < Rc < Value > > ) -> Value {
149
149
// @TODO generalize arity exceptions, and other exceptions
150
150
if args. is_empty ( ) {
151
151
return vec ! [ Symbol :: intern( "do" ) . to_rc_value( ) , Rc :: new( Value :: Nil ) ]
@@ -173,7 +173,7 @@ impl ToValue for NthFn {
173
173
}
174
174
}
175
175
impl IFn for NthFn {
176
- fn invoke ( & self , args : Vec < & Value > ) -> Value {
176
+ fn invoke ( & self , args : Vec < Rc < Value > > ) -> Value {
177
177
// @TODO generalize arity exceptions, and other exceptions
178
178
if args. len ( ) != 2 {
179
179
return Value :: Condition ( format ! (
@@ -183,13 +183,13 @@ impl IFn for NthFn {
183
183
}
184
184
// @TODO change iteration to work with Value references, or even change invoke to work on Rc<..>
185
185
// 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 {
188
188
return Value :: Condition ( format ! ( "Index cannot be negative; Index ({})" , ind) ) ;
189
189
}
190
- let ind = * ind as usize ;
190
+ let ind = ind as usize ;
191
191
192
- match args. get ( 0 ) . unwrap ( ) {
192
+ match & * * args. get ( 0 ) . unwrap ( ) {
193
193
Value :: PersistentList ( Cons ( head, tail, count) ) => {
194
194
let count = * count as usize ;
195
195
if ind >= count {
@@ -240,9 +240,9 @@ impl ToValue for ConcatFn {
240
240
}
241
241
}
242
242
impl 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 {
246
246
Value :: PersistentList ( plist) => {
247
247
Rc :: new ( plist. clone ( ) ) . iter ( ) . collect :: < Vec < Rc < Value > > > ( )
248
248
}
@@ -269,7 +269,7 @@ impl ToValue for PrintStringFn {
269
269
}
270
270
}
271
271
impl IFn for PrintStringFn {
272
- fn invoke ( & self , args : Vec < & Value > ) -> Value {
272
+ fn invoke ( & self , args : Vec < Rc < Value > > ) -> Value {
273
273
if args. len ( ) != 1 {
274
274
return Value :: Condition ( format ! (
275
275
"Wrong number of arguments given to function (Given: {}, Expected: {})" ,
@@ -291,7 +291,7 @@ impl ToValue for AssocFn {
291
291
}
292
292
}
293
293
impl IFn for AssocFn {
294
- fn invoke ( & self , args : Vec < & Value > ) -> Value {
294
+ fn invoke ( & self , args : Vec < Rc < Value > > ) -> Value {
295
295
// We don't want even args, because assoc works like
296
296
// (assoc {} :a 1) ;; 3 args
297
297
// (assoc {} :a 1 :b 2) ;; 5 args
@@ -303,12 +303,12 @@ impl IFn for AssocFn {
303
303
) ) ;
304
304
}
305
305
306
- if let Value :: PersistentListMap ( pmap) = args. get ( 0 ) . unwrap ( ) {
306
+ if let Value :: PersistentListMap ( pmap) = & * ( args. get ( 0 ) . unwrap ( ) . clone ( ) ) {
307
307
let mut retval = pmap. clone ( ) ;
308
308
for ( key_value, val_value) in args. into_iter ( ) . skip ( 1 ) . tuples ( ) {
309
309
let key = key_value. to_rc_value ( ) ;
310
310
let val = val_value. to_rc_value ( ) ;
311
- println ! ( "key: {:?}, val: {:?}" , key, val) ;
311
+ println ! ( "key: {:?}, val: {:?}" , key, val) ;
312
312
retval = pmap. assoc ( key, val) ;
313
313
}
314
314
return Value :: PersistentListMap ( retval) ;
0 commit comments