# HG changeset patch # User HackBot # Date 1357824546 0 # Node ID 5ce6274a65e9ffb41f5b092261dcafc6e7b7ad37 # Parent 3fef516b51802a21a97be0a1dbed6f76089455bc fetch http://sprunge.us/jXOV diff -r 3fef516b5180 -r 5ce6274a65e9 jXOV --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jXOV Thu Jan 10 13:29:06 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) +