From: pimjager Date: Thu, 26 May 2016 16:18:51 +0000 (+0200) Subject: lambdas without params, lambdas are now passed as vars instead of funcs X-Git-Url: https://git.martlubbers.net/?a=commitdiff_plain;h=b065681a6dad4cbec660a703c0553d30ce00ee37;p=cc1516.git lambdas without params, lambdas are now passed as vars instead of funcs --- diff --git a/examples/tempTest.spl b/examples/tempTest.spl index a5ac57d..6ef5e3d 100644 --- a/examples/tempTest.spl +++ b/examples/tempTest.spl @@ -24,10 +24,18 @@ l2(x) :: Int -> Void { return; } +repeat(f, n) { + var x = n; + while(x > 0) { + f(); + x = x-1; + } +} + main() { //var f = \x->print(x); - var z = map(\x->print(3), 1:2:[]); - var x = print(3); + //var z = map(\x->print(3), 1:2:[]); + repeat(\->print(0), 5); //var x = foldr(\x y->x+y, 0, 1:2:[]); //print(x); return; diff --git a/grammar/grammar.txt b/grammar/grammar.txt index b399311..06250b1 100644 --- a/grammar/grammar.txt +++ b/grammar/grammar.txt @@ -27,7 +27,7 @@ | '[]' | '(' ',' ')' | '"' '"' - ::= '\'+ '->' + ::= '\'* '->' ::= ('.' ('hd'|'tl'|'fst'|'snd))* ::= ['(' + ')'] ::= [',' ActArgs] diff --git a/parse.icl b/parse.icl index 426e47e..5af08db 100644 --- a/parse.icl +++ b/parse.icl @@ -159,7 +159,7 @@ parseValueExpr = //Operators in order of binding strength parseLambda :: Parser Token Expr parseLambda = LambdaExpr <$> peekPos - <*> (satTok BackslashToken *> some parseIdent) + <*> (satTok BackslashToken *> many parseIdent) <*> (satTok ArrowToken *> parseExpr) makeStrExpr :: Pos [Char] -> Expr diff --git a/sem.icl b/sem.icl index 47b6c1a..2f9e7d6 100644 --- a/sem.icl +++ b/sem.icl @@ -128,7 +128,7 @@ instance unfoldL_ Expr where fresh >>= \(IdType n) -> let f = ("2lambda_"+++n) in let fd = FunDecl p f args Nothing [] [ReturnStmt $ Just e] in - let fe = FunExpr p f [] [] in + let fe = VarExpr p (VarDef f []) in pure ([fd], fe) unfoldL_ (FunExpr p f es fs) = flattenT <$> mapM unfoldL_ es >>= \(fds, es_)-> pure (fds, FunExpr p f es_ fs)