File tree Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -77,6 +77,7 @@ impl Environment {
77
77
let concat_fn = rust_core:: ConcatFn { } ;
78
78
let print_string_fn = rust_core:: PrintStringFn { } ;
79
79
let assoc_fn = rust_core:: AssocFn { } ;
80
+ let get_fn = rust_core:: GetFn { } ;
80
81
// Hardcoded fns
81
82
let lexical_eval_fn = Value :: LexicalEvalFn { } ;
82
83
// Hardcoded macros
@@ -116,6 +117,7 @@ impl Environment {
116
117
) ;
117
118
environment. insert ( Symbol :: intern ( "nth" ) , nth_fn. to_rc_value ( ) ) ;
118
119
environment. insert ( Symbol :: intern ( "assoc" ) , assoc_fn. to_rc_value ( ) ) ;
120
+ environment. insert ( Symbol :: intern ( "get" ) , get_fn. to_rc_value ( ) ) ;
119
121
environment. insert ( Symbol :: intern ( "concat" ) , concat_fn. to_rc_value ( ) ) ;
120
122
environment. insert (
121
123
Symbol :: intern ( "print-string" ) ,
Original file line number Diff line number Diff line change @@ -289,3 +289,31 @@ impl IFn for AssocFn {
289
289
Value :: Nil
290
290
}
291
291
}
292
+
293
+ // General assoc fn; however, currently just implemented
294
+ // for our one map type, PersistentListMap
295
+ #[ derive( Debug , Clone ) ]
296
+ pub struct GetFn { }
297
+ impl ToValue for GetFn {
298
+ fn to_value ( & self ) -> Value {
299
+ Value :: IFn ( Rc :: new ( self . clone ( ) ) )
300
+ }
301
+ }
302
+ impl IFn for GetFn {
303
+ fn invoke ( & self , args : Vec < Rc < Value > > ) -> Value {
304
+ if args. len ( ) != 2 {
305
+ return Value :: Condition ( format ! (
306
+ "Wrong number of arguments given to function (Given: {}, Expected: 2)" ,
307
+ args. len( )
308
+ ) ) ;
309
+ }
310
+
311
+ if let Value :: PersistentListMap ( pmap) = & * ( args. get ( 0 ) . unwrap ( ) . clone ( ) ) {
312
+ let key = args. get ( 1 ) . unwrap ( ) ;
313
+ return pmap. get ( key) . to_value ( ) ;
314
+ }
315
+ // @TODO add error in here with erkk's new error tools
316
+
317
+ Value :: Nil
318
+ }
319
+ }
You can’t perform that action at this time.
0 commit comments