mirror of
https://github.com/teo3300/rust-mal.git
synced 2026-01-12 09:15:32 +01:00
Moving history path in mal
This commit is contained in:
12
src/eval.rs
12
src/eval.rs
@ -7,6 +7,16 @@ use crate::types::{MalArgs, MalErr, MalMap, MalRet, MalType};
|
||||
use std::borrow::Borrow;
|
||||
use std::rc::Rc;
|
||||
|
||||
macro_rules! forms {
|
||||
($($name:ident : $value:expr),*) => {
|
||||
$(
|
||||
const $name: &'static str = $value;
|
||||
)*
|
||||
};
|
||||
}
|
||||
|
||||
forms!(NAME_DEF : "def!");
|
||||
|
||||
/// Resolve the first element of the list as the function name and call it
|
||||
/// with the other elements as arguments
|
||||
fn eval_func(list: &MalType) -> CallRet {
|
||||
@ -162,7 +172,7 @@ pub fn eval(ast: &MalType, env: Env) -> MalRet {
|
||||
if let M::Sym(sym) = symbol {
|
||||
match sym.borrow() {
|
||||
// I don't like to borrow tho
|
||||
"def!" => return def_bang_form(args, env.clone()), // Set for env
|
||||
NAME_DEF => return def_bang_form(args, env.clone()), // Set for env
|
||||
"let*" => {(ast, env) = let_star_form(args, env.clone())?; continue;},
|
||||
"do" => {ast = do_form(args, env.clone())?; continue;},
|
||||
"if" => {ast = if_form(args, env.clone())?; continue;},
|
||||
|
||||
@ -17,7 +17,7 @@ mod functional {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn assert_fail() {
|
||||
fn assert() {
|
||||
test!("assert")
|
||||
}
|
||||
|
||||
|
||||
@ -70,6 +70,7 @@ pub fn interactive(env: Env) {
|
||||
const HISTORY: &str = ".mal-history";
|
||||
let home = get_home_path(&env).unwrap();
|
||||
let history = home + "/" + HISTORY;
|
||||
eval_str(format!("(def! MAL_HISTORY \"{}\")", history).as_str(), &env).unwrap();
|
||||
|
||||
// Using "Editor" instead of the standard I/O because I hate myself but not this much
|
||||
// TODO: remove unwrap and switch to a better error handling
|
||||
|
||||
Reference in New Issue
Block a user