# HG changeset patch # User HackBot # Date 1357824813 0 # Node ID 844a691cf7dc8fff949805decf00ecbdfe38226b # Parent 3336903b8bb57328ace89b895084ffcf646232a6 fetch http://sprunge.us/FdNb diff -r 3336903b8bb5 -r 844a691cf7dc FdNb --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/FdNb Thu Jan 10 13:33:33 2013 +0000 @@ -0,0 +1,30 @@ +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 ( + case (length args) of + 0 -> "Fiora" + otherwise -> args !! 0 + ) template) +