diff --git a/src/bin/main.rs b/src/bin/main.rs
index d2a5faa..908da89 100644
--- a/src/bin/main.rs
+++ b/src/bin/main.rs
@@ -14,6 +14,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
+#![feature(type_alias_impl_trait)]
use rustyline::error::ReadlineError;
use rustyline::Editor;
diff --git a/src/lib.rs b/src/lib.rs
index 97caf87..f1b6570 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -15,6 +15,8 @@
* along with this program. If not, see .
*/
+#![feature(type_alias_impl_trait)]
+
mod segment;
mod lex;
mod func;
diff --git a/src/vars.rs b/src/vars.rs
index 833bfb7..0500ee3 100644
--- a/src/vars.rs
+++ b/src/vars.rs
@@ -21,7 +21,7 @@ use std::collections::HashMap;
use std::env;
use crate::segment::{Ctr, Ast, ast_to_string};
use crate::eval::eval;
-use crate::func::{Function, Operation, Args, FTable};
+use crate::func::{Function, Operation, InternalOperation, Args, FTable};
/* Mapping between a string token and a tree of Segments
* The string token can be found in any Ctr::Symbol value
* it is expected that the trees stored are already evaluated
@@ -45,53 +45,58 @@ pub fn get_export(env_cfg: bool) -> Function {
loose_syms: true,
eval_lazy: true,
args: Args::Lazy(2),
- function: Operation::Internal(
- |a: Ast, b: Rc>, c: Rc>| -> Ctr {
- let inner = a.borrow_mut();
- match &inner.car {
- Ctr::Symbol(identifier) => {
- match &inner.cdr {
- Ctr::Seg(tree) => {
- match eval(tree.clone(), b.clone(), c.clone(), false) {
- Ok(seg) => {
- match seg {
- Ctr::Seg(val) => {
- let val_tmp = val.borrow().clone();
- define(b, identifier.to_string(), Rc::new(val_tmp.car));
- if env_cfg {
- match val_tmp.car {
- Ctr::Symbol(s) => env::set_var(identifier, s),
- Ctr::String(s) => env::set_var(identifier, s),
- Ctr::Integer(i) => env::set_var(identifier, format!("{}", i)),
- Ctr::Float(f) => env::set_var(identifier, format!("{}", f)),
- Ctr::Bool(b) => env::set_var(identifier, format!("{}", b)),
- Ctr::Seg(c) => env::set_var(identifier, ast_to_string(c)),
- Ctr::None => ()
- }
- }
- },
+ function: Operation::Internal(get_export_callback(env_cfg)),
+ };
+}
- _ => eprintln!("impossible args to export")
+fn get_export_callback(env_cfg: bool) -> InternalOperation {
+ |a: Ast, b: Rc>, c: Rc>| -> Ctr {
+ let inner = a.borrow_mut();
+ match &inner.car {
+ Ctr::Symbol(identifier) => {
+ match &inner.cdr {
+ Ctr::Seg(tree) => {
+ match eval(tree.clone(), b.clone(), c.clone(), false) {
+ Ok(seg) => {
+ match seg {
+ Ctr::Seg(val) => {
+ let val_tmp = val.borrow().clone();
+ define(b, identifier.to_string(), Rc::new(val_tmp.car));
+ if env_cfg {
+ match val_tmp.car {
+ Ctr::Symbol(s) => env::set_var(identifier, s),
+ Ctr::String(s) => env::set_var(identifier, s),
+ Ctr::Integer(i) => env::set_var(identifier, format!("{}", i)),
+ Ctr::Float(f) => env::set_var(identifier, format!("{}", f)),
+ Ctr::Bool(b) => env::set_var(identifier, format!("{}", b)),
+ Ctr::Seg(c) => env::set_var(identifier, ast_to_string(c)),
+ Ctr::None => ()
+ }
}
},
- Err(e) => eprintln!("couldnt eval symbol: {}", e)
+ _ => eprintln!("impossible args to export")
}
},
- Ctr::None => {
- (*b).borrow_mut().remove(identifier);
- },
-
- _ => eprintln!("args not in standard form")
+ Err(e) => eprintln!("couldnt eval symbol: {}", e)
}
},
- _ => eprintln!("first argument to export must be a symbol")
- }
+ Ctr::None => {
+ (*b).borrow_mut().remove(identifier);
+ if env_cfg {
+ // TODO: unset variable
+ }
+ },
- return Ctr::None;
- }
- )
- };
+ _ => eprintln!("args not in standard form")
+ }
+ },
+
+ _ => eprintln!("first argument to export must be a symbol")
+ }
+
+ return Ctr::None;
+ }
}