From 8fda79b9a9f26278319ca8ddd641c0ec94bdb7ec Mon Sep 17 00:00:00 2001 From: darkf Date: Wed, 23 Oct 2013 19:33:44 -0700 Subject: [PATCH] add loop BIF --- interp.hs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/interp.hs b/interp.hs index f2d23e1..f7e5a36 100644 --- a/interp.hs +++ b/interp.hs @@ -98,8 +98,16 @@ _getline UnitV = do _itos (IntV i) = return $ StrV $ show i _itos v = error $ "itos: not an int: " ++ show v +_loop args@(TupleV [fn@(FnV _ _), arg]) = do + v <- apply fn arg + if v == BoolV True then + _loop args + else return UnitV +_loop fn@(FnV _ _) = _loop $ TupleV [fn, UnitV] + initialState = ([stdout, stdin], [M.fromList [("id", FnV emptyEnv [(VarP "x", Var "x")]), + ("loop", Builtin $ BIF _loop), ("stdout", StreamV 0), ("putstr", Builtin $ BIF _putstr), ("putstrln", Builtin $ BIF (\x -> _putstr $ x +$ StrV "\n")),