summaryrefslogtreecommitdiff
path: root/fp1/week1/camil/2.3/MatchStrings.icl
diff options
context:
space:
mode:
authorMart Lubbers2015-04-16 21:22:20 +0200
committerMart Lubbers2015-04-16 21:22:20 +0200
commit6f604b19d3f5966e5c1d7c4fdf3703bd6ff0861c (patch)
tree96d580507249f7f58368476d9113007d4afcd748 /fp1/week1/camil/2.3/MatchStrings.icl
parentAdded student numbers (diff)
update to fp2 yay, public and licence
Diffstat (limited to 'fp1/week1/camil/2.3/MatchStrings.icl')
-rw-r--r--fp1/week1/camil/2.3/MatchStrings.icl48
1 files changed, 48 insertions, 0 deletions
diff --git a/fp1/week1/camil/2.3/MatchStrings.icl b/fp1/week1/camil/2.3/MatchStrings.icl
new file mode 100644
index 0000000..17859ae
--- /dev/null
+++ b/fp1/week1/camil/2.3/MatchStrings.icl
@@ -0,0 +1,48 @@
+implementation module MatchStrings
+
+import StdEnv
+
+head :: String -> Char
+head "" = abort "head uitgevoerd op lege string"
+head s = s.[0]
+
+tail :: String -> String
+tail "" = abort "tail uitgevoerd op lege string"
+tail s = s % (1, size s - 1)
+
+is_gelijk :: String String -> Bool
+is_gelijk "" "" = True
+is_gelijk a "" = False
+is_gelijk "" b = False
+is_gelijk a b = (head a == head b) && (is_gelijk (tail a) (tail b))
+
+is_deelstring :: String String -> Bool
+is_deelstring "" b = True
+is_deelstring a "" = False
+is_deelstring a b = is_gelijk a (b % (0, size a - 1)) || is_deelstring a (tail b)
+
+is_deel :: String String -> Bool
+is_deel "" b = True
+is_deel a "" = 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 "" "" = True
+is_match "" b = False
+is_match "*" "" = True
+is_match a "" = False
+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)
+
+//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"