summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xrpn.hs16
1 files changed, 9 insertions, 7 deletions
diff --git a/rpn.hs b/rpn.hs
index 64fdb89..b441db4 100755
--- a/rpn.hs
+++ b/rpn.hs
@@ -1,7 +1,8 @@
1#!/usr/bin/env runghc 1#!/usr/bin/env runghc
2 2
3import Control.Monad (join, sequence, forever) 3import Control.Monad (join, sequence, forever)
4import System.Environment (getArgs) 4import Control.Applicative
5import System.Environment
5import Data.Maybe (listToMaybe, isJust) 6import Data.Maybe (listToMaybe, isJust)
6import Data.Char (isSpace) 7import Data.Char (isSpace)
7import Data.List (nub) 8import Data.List (nub)
@@ -49,8 +50,7 @@ main = do
49 hSetBuffering stdin LineBuffering 50 hSetBuffering stdin LineBuffering
50 hSetBuffering stdout NoBuffering 51 hSetBuffering stdout NoBuffering
51 forever $ do 52 forever $ do
52 putStr "Formula: " 53 line <- maybe (putStr "Formula: " >> getLine) (<$ unsetEnv "FORMULA") =<< lookupEnv "FORMULA"
53 line <- getLine
54 let --symbols = join . join $ map (map words) . map lines $ args 54 let --symbols = join . join $ map (map words) . map lines $ args
55 symbols = words line 55 symbols = words line
56 unknownSymbols = nub $ filter (not . isKnownSymbol) symbols 56 unknownSymbols = nub $ filter (not . isKnownSymbol) symbols
@@ -62,10 +62,12 @@ main = do
62 putStrLn . pPrint $ evalExpVec symbols'' 62 putStrLn . pPrint $ evalExpVec symbols''
63 63
64clarifySymbol :: String -> IO [String] 64clarifySymbol :: String -> IO [String]
65clarifySymbol s = do 65clarifySymbol s = maybe clarify' (return . words) =<< lookupEnv s
66 putStr $ "Define " ++ s ++ ": " 66 where
67 line <- getLine 67 clarify' = do
68 return $ words line 68 putStr $ "Define " ++ s ++ ": "
69 line <- getLine
70 return $ words line
69 71
70isKnownSymbol :: String -> Bool 72isKnownSymbol :: String -> Bool
71isKnownSymbol s = or [ 73isKnownSymbol s = or [