Writing code from scratch is for idiots. ALWAYS look for pre-existing code and ALWAYS try and improve up on it, but doing a project from scratch is stupid and will only lead to headaches.
That is why perl is a bad language because perl programmers can't read each others codee
Name:
Anonymous2011-05-26 20:10
Lisp:
isInfixOf f [@_ Xs:_:@f @_] -> Xs
Haskell:
isInfixOf :: ByteString -> ByteString -> Bool
isInfixOf p s = isJust (findSubstring p s)
findSubstring :: ByteString -> ByteString -> Maybe Int
findSubstring f i = listToMaybe (findSubstrings f i)
findSubstrings :: ByteString -> ByteString -> [Int]
findSubstrings pat str
| null pat = [0 .. length str]
| otherwise = search 0 str
where
STRICT2(search)
search n s
| null s = []
| pat `isPrefixOf` s = n : search (n+1) (unsafeTail s)
| otherwise = search (n+1) (unsafeTail s)