allow non-deletion lines in a cloze

This commit is contained in:
2022-11-12 04:24:00 +00:00
parent 7b3f17201d
commit 32ad3a5f18
2 changed files with 21 additions and 15 deletions

View File

@@ -1,4 +1,4 @@
(reversed (basicText "dog") (basicText "chien"))
(reversed (typeText "owl") (typeText "chouette"))
(cloze "un" "deux" "trois" "quatre" "cinq")
(cloze "Numbers 1 through 5:" "?un" "?deux" "?trois" "?quatre" "?cinq")
(reversed (image "examples/france.png") (basicText "France"))

View File

@@ -33,7 +33,12 @@
(function :Void clozeShow [index textLines :StudyEngine engine :Void->Void cc]
(doFor [idx line] (enumerate textLines)
(engine.println (if (= idx index) "????" line)))
(engine.println
(if (= idx index)
"????"
(if (StringTools.startsWith line "?")
(line.substr 1)
line))))
(engine.input ->:Void _ (cc)))
(function :Void clozeScore [index textLines :StudyEngine engine :Int->Void resolve]
@@ -118,15 +123,19 @@
(card ,back ,front)))
(defMacro cloze [&builder b &body textLines]
(b.callSymbol "group"
(for i (range textLines.length)
`(card
(object
show (clozeShow.bind ,i ,textLines)
score ->:Void _ 0)
(object
show ->:Void _ 0
score (clozeScore.bind ,i ,textLines))))))
(let [cardDecls []]
(doFor [i line] (enumerate textLines)
(let [line (eval line)]
(when (StringTools.startsWith line "?")
(cardDecls.push
`(card
(object
show (clozeShow.bind ,i ,textLines)
score ->:Void _ 0)
(object
show ->:Void _ 0
score (clozeScore.bind ,i ,textLines)))))))
(b.callSymbol "group" cardDecls)))
(function :Void studyAll [&opt :StudyEngine engine]
(unless engine
@@ -144,7 +153,4 @@
(let [nextIndex (Std.random studyList.length)
nextToStudy (nth studyList nextIndex)]
(studyList.splice nextIndex 1)
(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
(nextToStudy engine (studyAll.bind engine)))))