Basic lambdas

This commit is contained in:
greg 2018-11-06 01:19:16 -08:00
parent be425860af
commit c6b4ed7ee4
2 changed files with 16 additions and 1 deletions

View File

@ -722,4 +722,15 @@ let z = if c {
"#; "#;
test_in_fresh_env!(source, r#"("x", "haha", "NIGH")"#); test_in_fresh_env!(source, r#"("x", "haha", "NIGH")"#);
} }
#[test]
fn basic_lambda_syntax() {
let source = r#"
let q = \(x, y) { x * y }
let x = q(5,2)
let y = \(m, n, o) { m + n + o }(1,2,3)
(x, y)
"#;
test_in_fresh_env!(source, r"(10, 6)");
}
} }

View File

@ -151,7 +151,11 @@ impl Expression {
} }
fn reduce_lambda(params: &Vec<FormalParam>, body: &Block, symbol_table: &SymbolTable) -> Expr { fn reduce_lambda(params: &Vec<FormalParam>, body: &Block, symbol_table: &SymbolTable) -> Expr {
unimplemented!() Expr::Func(Func::UserDefined {
name: None,
params: params.iter().map(|param| param.0.clone()).collect(),
body: body.iter().map(|stmt| stmt.reduce(symbol_table)).collect(),
})
} }
fn reduce_if_expression(discriminator: &Discriminator, body: &IfExpressionBody, symbol_table: &SymbolTable) -> Expr { fn reduce_if_expression(discriminator: &Discriminator, body: &IfExpressionBody, symbol_table: &SymbolTable) -> Expr {