diff --git a/projects/kiss-spaced-rep/src/kiss_spaced_rep/Card.hx b/projects/kiss-spaced-rep/src/kiss_spaced_rep/Card.hx index 8530dc95..4de9aeef 100644 --- a/projects/kiss-spaced-rep/src/kiss_spaced_rep/Card.hx +++ b/projects/kiss-spaced-rep/src/kiss_spaced_rep/Card.hx @@ -1,6 +1,11 @@ package kiss_spaced_rep; -typedef Card = { - front: String, - back: String +typedef CardSide = { + show: (Void->Void) -> Void, + score: (Int->Void) -> Void +}; + +typedef Card = { + front: CardSide, + back: CardSide }; diff --git a/projects/kiss-spaced-rep/src/kiss_spaced_rep/Main_.kiss b/projects/kiss-spaced-rep/src/kiss_spaced_rep/Main_.kiss index fe1187f8..21c3e030 100644 --- a/projects/kiss-spaced-rep/src/kiss_spaced_rep/Main_.kiss +++ b/projects/kiss-spaced-rep/src/kiss_spaced_rep/Main_.kiss @@ -1,8 +1,23 @@ (import datetime.DateTime - datetime.DateTimeInterval) + datetime.DateTimeInterval + kiss_spaced_rep.Card) (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 :CardSide basicText [:String text] + (object + show ->:Void [:Void->Void cc] { + (Sys.print text) + (.readLine (Sys.stdin)) + (cc) + } + score ->:Void [:Int->Void resolve] { + (Sys.print "Score (0-5): ") + (resolve (Std.parseInt (.readLine (Sys.stdin)))) + })) (defMacroVar cardId 0) @@ -12,7 +27,8 @@ cRepetitions (b.symbol "cRepetitions$cardId") cPreviousEaseFactor (b.symbol "cPreviousEaseFactor$cardId") cPreviousInterval (b.symbol "cPreviousInterval$cardId") - cNextDate (b.symbol "cNextDate$cardId")] + cNextDate (b.symbol "cNextDate$cardId") + cStudy (b.symbol "cStudy$cardId")] (setMacroVar cardId (+ cardId 1)) `{ (var ,cObject (object front ,front back ,back)) @@ -21,31 +37,53 @@ (savedVar :Int ,cPreviousInterval 0) (savedVar :Float ,cNextDate (DateTime.make)) - (function :Void ,cScore [:Int quality] - (localVar &mut interval 0) - (cond - ((>= quality 3) - (set interval (Math.ceil (case ,cRepetitions (0 1) (1 6) (more (* ,cPreviousEaseFactor ,cPreviousInterval)) (never otherwise)))) - (+= ,cRepetitions 1) - (set ,cPreviousEaseFactor (+ ,cPreviousEaseFactor (- 0.1 (* (- 5 quality) (+ 0.08 (* (- 5 quality ) 0.02))))))) - (true - (set ,cRepetitions 0) - (set interval 1))) - (set ,cPreviousEaseFactor (max 1.3 ,cPreviousEaseFactor)) - (set ,cPreviousInterval interval) - (doFor _ (range interval) - (set ,cNextDate #{DateTime.now() + oneDayInterval;}#))) + (let [:DateTime nextDate ,cNextDate] - (if #{DateTime.now() > nextDate;}# + (localFunction :Void ,cStudy [:Void->Void cc] + (localFunction :Void ,cScore [:Int quality] + (localVar &mut interval 0) + (cond + ((>= quality 3) + (set interval (Math.ceil (case ,cRepetitions (0 1) (1 6) (more (* ,cPreviousEaseFactor ,cPreviousInterval)) (never otherwise)))) + (+= ,cRepetitions 1) + (set ,cPreviousEaseFactor (+ ,cPreviousEaseFactor (- 0.1 (* (- 5 quality) (+ 0.08 (* (- 5 quality ) 0.02))))))) + (true + (set ,cRepetitions 0) + (set interval 1))) + (set ,cPreviousEaseFactor (max 1.3 ,cPreviousEaseFactor)) + (set ,cPreviousInterval interval) + (let [:DateTime cNextDate (DateTime.now)] + #{cNextDate += halfDayInterval;}# + (doFor _ (range (- interval 1)) + #{cNextDate += oneDayInterval;}#) + (set ,cNextDate cNextDate)) + (cc)) + + (if (or #{DateTime.now() > nextDate;}# (#if debug true false)) + (.show .front ,cObject + ->:Void + (.show .back ,cObject + ->:Void + (.score .back ,cObject ,cScore))) { - (Sys.print .front ,cObject) - (.readLine (Sys.stdin)) - (print .back ,cObject) - (Sys.print "Score (0-5): ") - (,cScore (Std.parseInt (.readLine (Sys.stdin)))) - } - (print "skipping a card until $(nextDate.toString)"))) + (print "skipping a card until $(nextDate.toString)") + (cc) + })) + (studyList.push ,cStudy)) })) -(card "dog" "chien") +(card (basicText "dog") (basicText "chien")) +(card (basicText "random") (basicText "fandom")) +(card (basicText "boots") (basicText "o'reilly")) + +(function :Void studyAll [] + (when studyList + (let [nextIndex (Std.random studyList.length) + nextToStudy (nth studyList nextIndex)] + (studyList.splice nextIndex 1) + (nextToStudy studyAll)))) +(studyAll) + +// 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 \ No newline at end of file