File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -27,6 +27,10 @@ pub use self::_divide_::*;
2727
2828pub ( crate ) mod _multiply_;
2929pub use self :: _multiply_:: * ;
30+
31+ pub ( crate ) mod ns;
32+ pub use self :: ns:: * ;
33+
3034//
3135// This module will hold core function and macro primitives that aren't special cases
3236// (like the quote macro, or let), and can't be implemented in clojure itself
@@ -113,7 +117,7 @@ impl EvalFn {
113117 EvalFn {
114118 enclosing_environment,
115119 }
116- }
120+ }
117121}
118122impl ToValue for EvalFn {
119123 fn to_value ( & self ) -> Value {
Original file line number Diff line number Diff line change 1+ use crate :: ifn:: IFn ;
2+ use crate :: value:: { ToValue , Value } ;
3+ use crate :: type_tag:: TypeTag ;
4+ use crate :: environment:: Environment ;
5+ use std:: rc:: Rc ;
6+
7+ use crate :: error_message;
8+
9+ #[ derive( Debug , Clone ) ]
10+ pub struct NsMacro {
11+ enclosing_environment : Rc < Environment >
12+ }
13+ impl NsMacro {
14+ pub fn new ( enclosing_environment : Rc < Environment > ) -> NsMacro {
15+ NsMacro {
16+ enclosing_environment,
17+ }
18+ }
19+ }
20+ impl ToValue for NsMacro {
21+ fn to_value ( & self ) -> Value {
22+ Value :: Macro ( Rc :: new ( self . clone ( ) ) )
23+ }
24+ }
25+ impl IFn for NsMacro {
26+ fn invoke ( & self , args : Vec < Rc < Value > > ) -> Value {
27+ if args. len ( ) != 1 {
28+ return error_message:: wrong_arg_count ( 1 , args. len ( ) ) ;
29+ }
30+
31+ let namespace = args. get ( 0 ) . unwrap ( ) ;
32+ match & * * namespace {
33+ Value :: Symbol ( sym) => {
34+ self . enclosing_environment . change_namespace ( sym. clone ( ) ) ;
35+ Value :: Nil
36+ } ,
37+ _ => error_message:: type_mismatch ( TypeTag :: Symbol , & * * namespace)
38+ }
39+
40+ }
41+ }
You can’t perform that action at this time.
0 commit comments