diff --git a/mute-interpreter/src/env/standard.rs b/mute-interpreter/src/env/standard.rs index a6a9757..f6a3c15 100644 --- a/mute-interpreter/src/env/standard.rs +++ b/mute-interpreter/src/env/standard.rs @@ -16,7 +16,7 @@ pub(super) fn standard() -> HashMap { ( "defun", inline! { - (macro* (name args body) ~(define (,name (fn* ,args ,body))) ) + (macro* (name args body) ~(define (,name (lambda ,args ,body))) ) }, ), ( diff --git a/mute-interpreter/src/evaluator.rs b/mute-interpreter/src/evaluator.rs index 70a6f69..3a0604c 100644 --- a/mute-interpreter/src/evaluator.rs +++ b/mute-interpreter/src/evaluator.rs @@ -385,7 +385,7 @@ mod test { #[case("(List.count {:a 1})", "1")] // Environment manipulation #[case("(define (asdf (+ 2 2))) (+ asdf 2)", "6")] - #[case("(define (add (fn* (a b) (+ a b)))) (add 1 2)", "3")] + #[case("(define (add (lambda (a b) (+ a b)))) (add 1 2)", "3")] #[case("(let* ((a 2)) (+ a 2))", "4")] // Branching #[case("(if true true false)", "true")] @@ -394,16 +394,16 @@ mod test { #[case("(if false 3)", "()")] // Functions #[case( - "(define (factorial (fn* (n) (if + "(define (factorial (lambda (n) (if (<= n 1) 1 (* n (factorial (- n 1))))))) (factorial 5)", "120" )] - #[case("((fn* (a) a) 3)", "3")] - #[case("((fn* (a) (+ a 2)) 1)", "3")] - #[case("((fn* (a b) (+ a b)) 1 2)", "3")] + #[case("((lambda (a) a) 3)", "3")] + #[case("((lambda (a) (+ a 2)) 1)", "3")] + #[case("((lambda (a b) (+ a b)) 1 2)", "3")] // Boolean operations #[case("(eq? 1 1)", "true")] #[case("(eq? 1 2)", "false")] @@ -439,12 +439,12 @@ mod test { #[case("(List.push-back [1 2 3] 4)", "[1 2 3 4]")] #[case("(List.pop-back [1 2 3 4])", "[1 2 3]")] // Iteration - #[case("(map '(1 2 3) (fn* (x) (* x x)))", "(1 4 9)")] - #[case("(filter '(1 2 3) (fn* (x) (> x 1)))", "(2 3)")] + #[case("(map '(1 2 3) (lambda (x) (* x x)))", "(1 4 9)")] + #[case("(filter '(1 2 3) (lambda (x) (> x 1)))", "(2 3)")] #[case("(reduce '(1 2 3 4) +)", "10")] - #[case("(reduce '(1 2 3 4) (fn* (lhs rhs) (+ lhs rhs)))", "10")] + #[case("(reduce '(1 2 3 4) (lambda (lhs rhs) (+ lhs rhs)))", "10")] #[case("(fold '(1 2 3 4) 5 +)", "15")] - #[case("(fold '(1 2 3 4) 5 (fn* (lhs rhs) (+ lhs rhs)))", "15")] + #[case("(fold '(1 2 3 4) 5 (lambda (lhs rhs) (+ lhs rhs)))", "15")] fn test_evaluator(#[case] input: &str, #[case] expected: &str) { dbg!(input); diff --git a/mute-macros/src/lib.rs b/mute-macros/src/lib.rs index 70771b0..bb293ff 100644 --- a/mute-macros/src/lib.rs +++ b/mute-macros/src/lib.rs @@ -91,8 +91,8 @@ mod tests { // Specials #[case("(define (a 1))")] #[case("(define (a 1) (b 2))")] - #[case("(fn* () (+ 1 1))")] - #[case("(fn* (a b) (+ a b))")] + #[case("(lambda () (+ 1 1))")] + #[case("(lambda (a b) (+ a b))")] #[case("(if true 1 2)")] fn test_format_node(#[case] input: &str) { set_snapshot_suffix!("{}", input); diff --git a/mute-macros/src/snapshots/mute_macros__tests__format_node@(lambda () (+ 1 1)).snap b/mute-macros/src/snapshots/mute_macros__tests__format_node@(lambda () (+ 1 1)).snap new file mode 100644 index 0000000..78ac5e8 --- /dev/null +++ b/mute-macros/src/snapshots/mute_macros__tests__format_node@(lambda () (+ 1 1)).snap @@ -0,0 +1,5 @@ +--- +source: mute-macros/src/lib.rs +expression: res +--- +Node::Function(vec![Node::List(vec![].into()), Node::List(vec![Node::Symbol("+".to_string()), Node::Int(1), Node::Int(1)].into())].into()) diff --git a/mute-macros/src/snapshots/mute_macros__tests__format_node@(lambda (a b) (+ a b)).snap b/mute-macros/src/snapshots/mute_macros__tests__format_node@(lambda (a b) (+ a b)).snap new file mode 100644 index 0000000..cc4be4a --- /dev/null +++ b/mute-macros/src/snapshots/mute_macros__tests__format_node@(lambda (a b) (+ a b)).snap @@ -0,0 +1,5 @@ +--- +source: mute-macros/src/lib.rs +expression: res +--- +Node::Function(vec![Node::List(vec![Node::Symbol("a".to_string()), Node::Symbol("b".to_string())].into()), Node::List(vec![Node::Symbol("+".to_string()), Node::Symbol("a".to_string()), Node::Symbol("b".to_string())].into())].into()) diff --git a/mute-parser/src/lexer.rs b/mute-parser/src/lexer.rs index 4f3b4db..cfa1b84 100644 --- a/mute-parser/src/lexer.rs +++ b/mute-parser/src/lexer.rs @@ -211,7 +211,7 @@ fn read_ident(input: &mut Peekable, first: char) -> Token { "true" => Token::True, "false" => Token::False, "nil" => Token::Nil, - "fn*" => Token::Function, + "lambda" => Token::Function, "macro*" => Token::Macro, "define" => Token::Define, "let*" => Token::Let, diff --git a/mute-parser/src/node.rs b/mute-parser/src/node.rs index b991215..3c55d65 100644 --- a/mute-parser/src/node.rs +++ b/mute-parser/src/node.rs @@ -111,7 +111,7 @@ impl std::fmt::Display for Node { Node::Define(body) => write!(f, "(define {})", reduce_list(body)), Node::Let(body) => write!(f, "(let* {})", reduce_list(body)), Node::Macro(body) => write!(f, "(macro* {})", reduce_list(body)), - Node::Function(body) => write!(f, "(fn* {})", reduce_list(body)), + Node::Function(body) => write!(f, "(lambda {})", reduce_list(body)), Node::If(body) => write!(f, "(if {})", reduce_list(body)), Node::Quote(node) => write!(f, "'{node}"),