summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGregor Kleen <gkleen@yggdrasil.li>2016-03-01 05:15:01 +0100
committerGregor Kleen <gkleen@yggdrasil.li>2016-03-01 05:15:01 +0100
commit1554095368e65bf6f1c4d0f0106ae4516117964a (patch)
tree1ed3af434943d7eec32c8557e2a2623c6d98627e
parent680e02eb3a6ae88adced9103dee2171b492eaaa4 (diff)
downloadgausshs-1554095368e65bf6f1c4d0f0106ae4516117964a.tar
gausshs-1554095368e65bf6f1c4d0f0106ae4516117964a.tar.gz
gausshs-1554095368e65bf6f1c4d0f0106ae4516117964a.tar.bz2
gausshs-1554095368e65bf6f1c4d0f0106ae4516117964a.tar.xz
gausshs-1554095368e65bf6f1c4d0f0106ae4516117964a.zip
Support for reading formula from environment
-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 [