# HG changeset patch # User HackBot # Date 1357824624 0 # Node ID 5338ba60ba90fab4048ee38cabaa73b3b714ee8e # Parent ec6018972dc0a0217fca853ab7a7a71959fea4c1 mv gktemp/target gktemp/target.hs diff -r ec6018972dc0 -r 5338ba60ba90 gktemp/target --- a/gktemp/target Thu Jan 10 13:29:55 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,26 +0,0 @@ -import Data.List -import Data.Char -import System.Environment - -standardURL = "http://esolangs.org/wiki/Main_Page" - - -replace :: (Eq a) => [a] -> [a] -> [a] -> [a] -replace _ _ [] = [] -replace old new (y:ys) = - case stripPrefix old (y:ys) of - Nothing -> y : replace old new ys - Just ys' -> new ++ replace old new ys' - -applyGenTemplate :: String -> String -> String -> String -- nick url template -> result -applyGenTemplate nick url template = nick ++ ": " ++ replace "^" nick (replace "@" url template) - -applyTemplate :: String -> String -> String -- nick template -> result -applyTemplate nick template = applyGenTemplate nick standardURL template - - -main = do - args <- getArgs - template <- getLine - putStrLn (applyTemplate (args !! 0) template) - diff -r ec6018972dc0 -r 5338ba60ba90 gktemp/target.hs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gktemp/target.hs Thu Jan 10 13:30:24 2013 +0000 @@ -0,0 +1,26 @@ +import Data.List +import Data.Char +import System.Environment + +standardURL = "http://esolangs.org/wiki/Main_Page" + + +replace :: (Eq a) => [a] -> [a] -> [a] -> [a] +replace _ _ [] = [] +replace old new (y:ys) = + case stripPrefix old (y:ys) of + Nothing -> y : replace old new ys + Just ys' -> new ++ replace old new ys' + +applyGenTemplate :: String -> String -> String -> String -- nick url template -> result +applyGenTemplate nick url template = nick ++ ": " ++ replace "^" nick (replace "@" url template) + +applyTemplate :: String -> String -> String -- nick template -> result +applyTemplate nick template = applyGenTemplate nick standardURL template + + +main = do + args <- getArgs + template <- getLine + putStrLn (applyTemplate (args !! 0) template) +