misc!: rename fn* to lambda

I just like it more
This commit is contained in:
Roman Godmaire 2024-07-15 19:34:45 -04:00
parent fa8195458d
commit 5fa8e1a6ae
7 changed files with 24 additions and 14 deletions

View file

@ -16,7 +16,7 @@ pub(super) fn standard() -> HashMap<String, Value> {
(
"defun",
inline! {
(macro* (name args body) ~(define (,name (fn* ,args ,body))) )
(macro* (name args body) ~(define (,name (lambda ,args ,body))) )
},
),
(

View file

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

View file

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

View file

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

View file

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

View file

@ -211,7 +211,7 @@ fn read_ident(input: &mut Peekable<Chars>, 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,

View file

@ -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}"),