From c6b4ed7ee408071a2a7b618cfb1ea1f49f16553a Mon Sep 17 00:00:00 2001 From: greg Date: Tue, 6 Nov 2018 01:19:16 -0800 Subject: [PATCH] Basic lambdas --- schala-lang/language/src/eval.rs | 11 +++++++++++ schala-lang/language/src/reduced_ast.rs | 6 +++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/schala-lang/language/src/eval.rs b/schala-lang/language/src/eval.rs index c3c99ee..d8719de 100644 --- a/schala-lang/language/src/eval.rs +++ b/schala-lang/language/src/eval.rs @@ -722,4 +722,15 @@ let z = if c { "#; 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)"); + } } diff --git a/schala-lang/language/src/reduced_ast.rs b/schala-lang/language/src/reduced_ast.rs index 09a0bef..5491c2e 100644 --- a/schala-lang/language/src/reduced_ast.rs +++ b/schala-lang/language/src/reduced_ast.rs @@ -151,7 +151,11 @@ impl Expression { } fn reduce_lambda(params: &Vec, 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 {