flexible continuations-based kiss-spaced-rep

This commit is contained in:
2022-11-02 19:28:11 +00:00
parent e7360e5cb5
commit dbd0c62a1a
2 changed files with 71 additions and 28 deletions

View File

@@ -1,6 +1,11 @@
package kiss_spaced_rep; package kiss_spaced_rep;
typedef Card = { typedef CardSide = {
front: String, show: (Void->Void) -> Void,
back: String score: (Int->Void) -> Void
};
typedef Card = {
front: CardSide,
back: CardSide
}; };

View File

@@ -1,8 +1,23 @@
(import (import
datetime.DateTime 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 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) (defMacroVar cardId 0)
@@ -12,7 +27,8 @@
cRepetitions (b.symbol "cRepetitions$cardId") cRepetitions (b.symbol "cRepetitions$cardId")
cPreviousEaseFactor (b.symbol "cPreviousEaseFactor$cardId") cPreviousEaseFactor (b.symbol "cPreviousEaseFactor$cardId")
cPreviousInterval (b.symbol "cPreviousInterval$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)) (setMacroVar cardId (+ cardId 1))
`{ `{
(var ,cObject (object front ,front back ,back)) (var ,cObject (object front ,front back ,back))
@@ -21,31 +37,53 @@
(savedVar :Int ,cPreviousInterval 0) (savedVar :Int ,cPreviousInterval 0)
(savedVar :Float ,cNextDate (DateTime.make)) (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] (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) (print "skipping a card until $(nextDate.toString)")
(.readLine (Sys.stdin)) (cc)
(print .back ,cObject) }))
(Sys.print "Score (0-5): ") (studyList.push ,cStudy))
(,cScore (Std.parseInt (.readLine (Sys.stdin))))
}
(print "skipping a card until $(nextDate.toString)")))
})) }))
(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