summaryrefslogtreecommitdiff
path: root/week1/mart/MatchStrings.icl
diff options
context:
space:
mode:
authorMart Lubbers2015-02-05 21:05:17 +0100
committerMart Lubbers2015-02-05 21:05:17 +0100
commit634f2d65ded5ad683c65efdb900992e89471018c (patch)
treec9013718cb965c459b446ffc9fafbdf4894a1d62 /week1/mart/MatchStrings.icl
parentInitial commit (diff)
week1: mart
Diffstat (limited to 'week1/mart/MatchStrings.icl')
-rw-r--r--week1/mart/MatchStrings.icl54
1 files changed, 54 insertions, 0 deletions
diff --git a/week1/mart/MatchStrings.icl b/week1/mart/MatchStrings.icl
new file mode 100644
index 0000000..f10df45
--- /dev/null
+++ b/week1/mart/MatchStrings.icl
@@ -0,0 +1,54 @@
+implementation module MatchStrings
+
+import StdEnv
+
+head :: String -> Char
+head "" = abort "Empty String"
+head s = s.[0]
+
+tail :: String -> String
+tail "" = abort "Empty String"
+tail s = s % (1, size s - 1)
+
+is_gelijk :: String String -> Bool
+is_gelijk "" "" = True
+is_gelijk a b = (size a == size b) && (head a == head b) && is_gelijk (tail a) (tail b)
+
+is_deelstring :: String String -> Bool
+is_deelstring _ "" = False
+is_deelstring a b = is_begin a b || is_deelstring a (tail b)
+
+is_begin :: String String -> Bool
+is_begin "" _ = True
+is_begin _ "" = False
+is_begin a b = head a == head b && is_begin (tail a) (tail b)
+
+is_deel :: String String -> Bool
+is_deel "" _ = True
+is_deel _ "" = False
+is_deel a b = head a == head b && is_deel (tail a) (tail b) || is_deel a (tail b)
+
+is_match :: String String -> Bool
+is_match a b = is_begin_match a b || size b > 0 && is_begin_match a (tail b)
+
+is_begin_match :: String String -> Bool
+is_begin_match "" _ = True
+is_begin_match a "" = head a == '*' && size a == 1
+is_begin_match a b
+| head a == '.' || head a == head b = is_begin_match (tail a) (tail b)
+| head a == '*' = is_begin_match a (tail b) || is_begin_match (tail a) b
+| otherwise = False
+
+//Start= (head pink_floyd, tail pink_floyd)
+//Start= is_gelijk "" " "
+//Start= is_deelstring "there" pink_floyd
+//Start= is_deelstring "there" marillion
+//Start= is_deel "there" marillion
+//Start= is_deel "she and her" pink_floyd
+//Start= is_deel radiohead pink_floyd
+//Start= is_match "*.here*.here*." pink_floyd
+//Start= is_match ".here.here." pink_floyd
+
+pink_floyd= "Is there anybody in there?"
+marillion= "Just for the record"
+radiohead= "There there"