From 492e763904e714f68d2c997f4e66ae479021dd2f Mon Sep 17 00:00:00 2001
From: p9malino26 <pm3g19@soton.ac.uk>
Date: Wed, 21 Apr 2021 11:34:24 +0100
Subject: [PATCH] Able to omit set name if set function takes in last output
 result

---
 Eval.hs           | 6 +++++-
 Parser.y          | 1 +
 sampleprogram.txt | 2 +-
 3 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/Eval.hs b/Eval.hs
index b5f6051..7f9a370 100644
--- a/Eval.hs
+++ b/Eval.hs
@@ -39,7 +39,11 @@ eval env expr = let (eval', evalFull') = (eval env, evalFull env) in case expr o
     _ -> expr
 
 evalControl1 :: Environment -> Expr -> Expr
-evalControl1 env (Control _ (currentExpr:exprs)) = let output = eval env currentExpr in Control output exprs
+evalControl1 env (Control last (currentExpr:exprs)) = let output = eval env currentExprFull in Control output exprs
+    where 
+        currentExprFull = case currentExpr of
+            (FuncCall func [] args) -> FuncCall func [last] args
+            _ -> currentExpr
 
 evalFull = eval
 --evalFull env (Set xs) = Set (map (eval env) xs) -- evaluates expression fully (not just weak head normal form)
diff --git a/Parser.y b/Parser.y
index 030a148..8be3046 100644
--- a/Parser.y
+++ b/Parser.y
@@ -47,6 +47,7 @@ SetFuncCalls : SetFuncCall    {[$1]}
                 | SetFuncCall';' SetFuncCalls   {$1:$3}
 
 SetFuncCall : filter '['SetName']' '('Func')' {FuncCall (PredefFunc Filter) [Var $3] [$6]}
+	| filter '('Func')' {FuncCall (PredefFunc Filter) [] [$3]}
 
 Func : '\\' '(' VarNames ')' "->" Expr {FuncDef [] $3 $6}
 
diff --git a/sampleprogram.txt b/sampleprogram.txt
index f7c9aac..25021ec 100644
--- a/sampleprogram.txt
+++ b/sampleprogram.txt
@@ -2,4 +2,4 @@
 SampleSet
 
 .out
-filter[SampleSet](\(r) -> r[0] == "hello")
\ No newline at end of file
+filter (\(r) -> r[0] == "hello")
\ No newline at end of file
-- 
GitLab