Added my code
[fp1415.git] / week1 / camil / 2.3 / MatchStrings.icl
1 implementation module MatchStrings
2
3 import StdEnv
4
5 head :: String -> Char
6 head "" = abort "head uitgevoerd op lege string"
7 head s = s.[0]
8
9 tail :: String -> String
10 tail "" = abort "tail uitgevoerd op lege string"
11 tail s = s % (1, size s - 1)
12
13 is_gelijk :: String String -> Bool
14 is_gelijk "" "" = True
15 is_gelijk a "" = False
16 is_gelijk "" b = False
17 is_gelijk a b = (head a == head b) && (is_gelijk (tail a) (tail b))
18
19 is_deelstring :: String String -> Bool
20 is_deelstring "" b = True
21 is_deelstring a "" = False
22 is_deelstring a b = is_gelijk a (b % (0, size a - 1)) || is_deelstring a (tail b)
23
24 is_deel :: String String -> Bool
25 is_deel "" b = True
26 is_deel a "" = False
27 is_deel a b = head a == head b && is_deel (tail a) (tail b) || is_deel a (tail b)
28
29 is_match :: String String -> Bool
30 is_match "" "" = True
31 is_match "" b = False
32 is_match "*" "" = True
33 is_match a "" = False
34 is_match a b = (head a == '.' || head a == head b) && is_match (tail a) (tail b) || head a == '*' && (is_match a (tail b) || is_match (tail a) b)
35
36 //Start = (head pink_floyd, tail pink_floyd)
37 //Start = is_gelijk "" " "
38 //Start = is_deelstring "there" pink_floyd
39 //Start = is_deelstring "there" marillion
40 //Start = is_deel "there" marillion
41 //Start = is_deel "she and her" pink_floyd
42 //Start = is_deel radiohead pink_floyd
43 //Start = is_match "*.here*.here*." pink_floyd
44 //Start = is_match ".here.here." pink_floyd
45
46 pink_floyd = "Is there anybody in there?"
47 marillion = "Just for the record"
48 radiohead = "There there"