From: Mart Lubbers Date: Wed, 29 Apr 2015 17:17:10 +0000 (+0200) Subject: GetallenRaden done:) X-Git-Url: https://git.martlubbers.net/?a=commitdiff_plain;h=b888368716834847f4ea3ab32fcf8191a904bcce;p=fp1415.git GetallenRaden done:) --- diff --git a/fp2/week3/mart/GetallenRaden.icl b/fp2/week3/mart/GetallenRaden.icl index 37584fb..74678aa 100644 --- a/fp2/week3/mart/GetallenRaden.icl +++ b/fp2/week3/mart/GetallenRaden.icl @@ -1,14 +1,10 @@ module GetallenRaden -/* Dynamics werken alleen met de 32-bit versie van de Clean compiler. - (*) Gebruik Environment 'Experimental' - (*) In Project:Project Options: zet vlag 'Enable dynamics' aan -*/ import StdEnv -import StdDynamic, StdDynamicFileIO // nodig voor dynamics en dynamics in files -import StdFileSelect // platform file-selector dialoog +import StdDynamic, StdDynamicFileIO +import StdFileSelect -// Generation program +// Example generation program //fib :: [Int] //fib = [fib` i \\ i <- [0..]] // where @@ -23,16 +19,32 @@ makeSeq :: Dynamic -> [Int] makeSeq (x :: [Int]) = x makeSeq _ = abort "You selected a file not containing a sequence" -loadSeq :: String *World -> *([Int], *World) +basename :: String Int -> String +basename s 0 = toString s.[0] +basename s n = let c = toString s.[n] in if (c == "\\") "" ((basename s (n-1)) +++ c) + +loadSeq :: String *World -> *([Int], String, *World) loadSeq s world # s = let l = size s in s % (0, l-5) # (ok, dyn, world) = readDynamic s world | not ok = abort "You didn't select a dynamic file" -| otherwise = (makeSeq dyn, world) +| otherwise = (makeSeq dyn, basename s ((size s)-1), world) + +play :: *File String [Int] Int Int -> *File +play io _ _ _ 5 = io <<< "Congratulations, you had 5 correct answers\n" +play io seqname [nextnum:sequence] currentnum correct +# io = io <<< (seqname +++ "[" +++ toString currentnum +++ "] = " +++ toString nextnum +++ "\n") +# (ok, guessednumber, io) = freadi io +| not ok = play (snd (freadline io)) seqname sequence (currentnum + 1) correct +# (io, correct) = if (guessednumber == hd sequence) (io, correct+1) (io <<< "Incorrect...\n", correct) += play (snd (freadline io)) seqname sequence (currentnum + 1) correct -Start :: *World -> ([Int], *World) +Start :: *World -> *World Start world # (inputfilepath, world) = selectInputFile world | isNothing inputfilepath = abort "Please select a file" -# (sequence, world) = loadSeq (fromJust inputfilepath) world -| otherwise = (take 20 sequence, world) +# (sequence, sequencename, world) = loadSeq (fromJust inputfilepath) world +# (io, world) = stdio world +# io = (play io sequencename sequence 0 0) <<< "Press any key to close" +# (_, world) = fclose io world += world diff --git a/fp2/week3/mart/GetallenRaden.prj b/fp2/week3/mart/GetallenRaden.prj index b3af0da..e857306 100644 --- a/fp2/week3/mart/GetallenRaden.prj +++ b/fp2/week3/mart/GetallenRaden.prj @@ -24,7 +24,7 @@ Global Time: False Stack: False Output - Output: ShowConstructors + Output: NoReturnType Font: Courier FontSize: 9 WriteStdErr: False