Kiss-spaced-rep support flexible engine object

This commit is contained in:
2022-11-03 22:04:56 +00:00
parent 0a44a9a2b6
commit b1567e9f66
4 changed files with 59 additions and 37 deletions

View File

@@ -1,8 +1,8 @@
package kiss_spaced_rep;
typedef CardSide = {
show: (Void->Void) -> Void,
score: (Int->Void) -> Void
show: (StudyEngine, Void->Void) -> Void,
score: (StudyEngine, Int->Void) -> Void
};
typedef Card = {

View File

@@ -1,44 +1,43 @@
(import
datetime.DateTime
datetime.DateTimeInterval
kiss_spaced_rep.Card)
kiss_spaced_rep.Card
kiss_spaced_rep.StudyEngine)
(var oneDayInterval (DateTimeInterval.create (DateTime.make 1970 1 1) (DateTime.make 1970 1 2)))
(var halfDayInterval (DateTimeInterval.create (DateTime.make 1970 1 1 0) (DateTime.make 1970 1 1 12)))
(var studyList [])
(function :Void confirmShow [text :Void->Void cc]
(Sys.print text)
(.readLine (Sys.stdin))
(function :Void confirmShow [text :StudyEngine engine :Void->Void cc]
(engine.printCC text cc))
(function :Void basicScore [text :StudyEngine engine :Int->Void resolve]
(engine.println text)
(engine.print "Score (0-5): ")
(engine.input ->:Void str (resolve (Std.parseInt str))))
(function :Void noConfirmShow [text :StudyEngine engine :Void->Void cc]
(engine.println text)
(cc))
(function :Void basicScore [text :Int->Void resolve]
(Sys.println text)
(Sys.print "Score (0-5): ")
(resolve (Std.parseInt (.readLine (Sys.stdin)))))
(function :Void noConfirmShow [text :Void->Void cc]
(Sys.println text)
(cc))
(function :Void typeScore [text :Int->Void resolve]
(Sys.print "Your answer: ")
(function :Void typeScore [text :StudyEngine engine :Int->Void resolve]
(engine.print "Your answer: ")
(engine.input ->:Void input
(cond
((= text (.readLine (Sys.stdin)))
(Sys.println "Correct!")
((= text input)
(engine.println "Correct!")
(resolve 5))
(true
(Sys.println "Wrong! Correct answer was $text")
(resolve 0))))
(engine.println "Wrong! Correct answer was $text")
(resolve 0)))))
(function :Void clozeShow [index textLines :Void->Void cc]
(function :Void clozeShow [index textLines :StudyEngine engine :Void->Void cc]
(doFor [idx line] (enumerate textLines)
(Sys.println (if (= idx index) "????" line)))
(.readLine (Sys.stdin))
(cc))
(engine.println (if (= idx index) "????" line)))
(engine.input ->:Void _ (cc)))
(function :Void clozeScore [index textLines :Int->Void resolve]
(basicScore (nth textLines index) resolve))
(function :Void clozeScore [index textLines :StudyEngine engine :Int->Void resolve]
(basicScore (nth textLines index) engine resolve))
(function :CardSide basicText [:String text]
(object
@@ -69,7 +68,7 @@
(savedVar :Float ,cNextDate (DateTime.make))
(let [:DateTime nextDate ,cNextDate]
(localFunction :Void ,cStudy [:Void->Void cc]
(localFunction :Void ,cStudy [:StudyEngine engine :Void->Void cc]
(localFunction :Void ,cScore [:Int quality]
(localVar &mut interval 0)
(cond
@@ -90,11 +89,11 @@
(cc))
(if (or #{DateTime.now() > nextDate;}# (#if debug true false))
(.show .front ,cObject
(.show .front ,cObject engine
->:Void
(.score .back ,cObject ,cScore))
(.score .back ,cObject engine ,cScore))
{
(print "skipping a card until $(nextDate.toString)")
(engine.println "skipping a card until $(nextDate.toString)")
(cc)
}))
(studyList.push ,cStudy))
@@ -117,12 +116,22 @@
show ->:Void _ 0
score (clozeScore.bind ,i ,textLines))))))
(function :Void studyAll []
(function :Void studyAll [&opt :StudyEngine engine]
(unless engine
(set engine
(object
clear ->:Void {}
print ->:Void text (Sys.print text)
println ->:Void text (Sys.println text)
printCC ->:Void [text cc] {(Sys.print text)(.readLine (Sys.stdin))(cc)}
printlnCC ->:Void [text cc] {(Sys.println text)(.readLine (Sys.stdin))(cc)}
showImageCC ->:Void [path cc] 0
input ->:Void resolve (resolve (.readLine (Sys.stdin))))))
(when studyList
(let [nextIndex (Std.random studyList.length)
nextToStudy (nth studyList nextIndex)]
(studyList.splice nextIndex 1)
(nextToStudy studyAll))))
(nextToStudy engine (studyAll.bind engine)))))
// TODO make a note macro that defines a card then defines it in reverse
// TODO make a cloze macro that makes a card with each group deleted

View File

@@ -0,0 +1,13 @@
package kiss_spaced_rep;
typedef Continuation = Void -> Void;
typedef StudyEngine = {
clear: Void -> Void,
print: (String) -> Void,
println: (String) -> Void,
printCC: (String, Continuation) -> Void,
printlnCC: (String, Continuation) -> Void,
showImageCC: (String, Continuation) -> Void,
input: (String->Void) -> Void
};

View File

@@ -1,3 +1,3 @@
#! /bin/bash
haxe -D cards=$(pwd)/examples/Nonsense.kiss build.hxml
haxe -D cards=$(pwd)/examples/French.kiss build.hxml