Moving history path in mal

This commit is contained in:
teo3300
2024-01-27 18:38:41 +09:00
parent d8f431b739
commit 74a8ae0d5e
5 changed files with 31 additions and 8 deletions

View File

@ -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;},

View File

@ -17,7 +17,7 @@ mod functional {
}
#[test]
fn assert_fail() {
fn assert() {
test!("assert")
}

View File

@ -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