Permalink
Browse files

Some misc changes in how print works in an attempt to fix for..in..@.…

… It didn't work. :(
  • Loading branch information...
1 parent fccfe68 commit 5620ba48eb6ad7c4d1d2e09a232a330fb33e66df @TikhonJelvis committed Feb 19, 2012
Showing with 9 additions and 7 deletions.
  1. +3 −3 src/TPL/Eval.hs
  2. +3 −3 src/TPL/Native.hs
  3. +1 −1 src/TPL/Parse.hs
  4. +2 −0 src/base.tpl
View
6 src/TPL/Eval.hs
@@ -95,8 +95,8 @@ extractId env (Id name) = do res <- get env name
Id str -> return str
_ -> extractId env res
extractId _ (String str) = return str
-extractId _ (Lambda [] (Id name)) = return name
extractId _ (Function _ [] (Id name)) = return name
+extractId env (Function _ [] val) = extractId env val
extractId _ val = throwError . Default $ "Invalid variable: " ++ show val
_get :: TPLOperation
@@ -119,8 +119,8 @@ with env withArgs@[List bindings, Function closure args body] =
do res <- mapM (toBinding . squash) bindings >>= liftIO . bindVars closure
apply env (Function res args body) []
where toBinding (Expression [Id "->", name, val]) = toBinding $ List [name, val]
- toBinding (List [nameExp, val]) = do evalled <- eval env val
- name <- extractId env nameExp
+ toBinding (List [nameExp, val]) = do evalled <- eval env val
+ name <- extractId env nameExp
return (name, evalled)
toBinding _ = throwError $ BadNativeCall "with" withArgs
with env [bindings, Id name] = do val <- get env name
View
6 src/TPL/Native.hs
@@ -15,7 +15,7 @@ eagerNatives :: [(String, TPLOperation)]
eagerNatives = [("+", numOp (+)), ("-", numOp (-)), ("*", numOp (*)),
("/", numOp div), ("=", eqOp (==)), ("/=", eqOp (/=)),
(">", eqNumOp (>)), ("><", strOp (++)), (":", cons),
- ("open", open), ("print", printTPL), ("substr", substr),
+ ("open", open), ("_print", _print), ("substr", substr),
("length", len), ("_if", ifTPL)]
precedenceOf :: Env -> String -> IOThrowsError Integer
@@ -34,8 +34,8 @@ open _ args = do res <- mapM (liftThrows <<< extract <=< toString) args
result <- concat <$> mapM (liftIO . readFile) res
return $ String result
-printTPL :: TPLOperation
-printTPL _ args = mapM (liftIO . putStrLn . show) args >> return Null
+_print :: TPLOperation
+_print _ args = mapM (liftIO . putStrLn . show) args >> return Null
substr :: TPLOperation
substr _ [String str, Number start, Number end] =
View
2 src/TPL/Parse.hs
@@ -84,7 +84,7 @@ delayedExp :: Parser TPLValue
delayedExp = char '$' *> (Lambda [] <$> atom)
atom :: Parser TPLValue
-atom = lexeme $ lambda
+atom = lexeme $ lambda
<|> bool
<|> nullExp
<|> identifier
View
2 src/base.tpl
@@ -1,5 +1,7 @@
force x := x
+print x := _print x
+
precedence (+) 5
precedence (-) 5
precedence (*) 4

0 comments on commit 5620ba4

Please sign in to comment.