diff options
| author | Craig Jennings <c@cjennings.net> | 2026-05-27 21:28:20 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-05-27 21:28:20 -0500 |
| commit | 6e3f2d278d9598c6838428ee510445f51888bb30 (patch) | |
| tree | 98ca78149861191d32012a4148b1ce239cf08a75 /org-drill.el | |
| parent | eaa0a53f807b44d8a4bf72f3de562b011f69756e (diff) | |
| download | org-drill-6e3f2d278d9598c6838428ee510445f51888bb30.tar.gz org-drill-6e3f2d278d9598c6838428ee510445f51888bb30.zip | |
refactor: take card-state in org-drill-determine-next-interval-sm2
Stage 3 of #147. sm2 now takes (state quality) instead of seven positional args, binding the recall fields from the struct at the top so the algorithm body is unchanged. The smart-reschedule and hypothetical-next-review-date call sites pass the state they already hold, which drops the per-branch accessor unpacking.
I kept the return as the existing positional list rather than restructuring it too. The goal is reducing the input signature, and changing the return shape would force the shared test extractors and every return-read to change for no real gain. A testutil adapter, test-scheduler--call-sm2, packs positional args into the struct, so the test call sites stay readable as the documented algorithm inputs and the migration is a one-symbol rename per call.
Diffstat (limited to 'org-drill.el')
| -rw-r--r-- | org-drill.el | 37 |
1 files changed, 15 insertions, 22 deletions
diff --git a/org-drill.el b/org-drill.el index fd6f24e..7046ade 100644 --- a/org-drill.el +++ b/org-drill.el @@ -1232,13 +1232,12 @@ caller passes the scheduler's next-interval there)." (org-drill-round-float (org-drill-card-state-ease state) 3)))) ;;; SM2 Algorithm ============================================================= -(defun org-drill-determine-next-interval-sm2 (last-interval n ef quality - failures meanq total-repeats) - "Arguments: -- LAST-INTERVAL -- the number of days since the item was last reviewed. -- REPEATS -- the number of times the item has been successfully reviewed -- EF -- the \\='easiness factor\\=' -- QUALITY -- 0 to 5 +(defun org-drill-determine-next-interval-sm2 (state quality) + "Return the SM2 schedule for STATE after a review of recall QUALITY (0-5). + +STATE is an `org-drill-card-state' carrying LAST-INTERVAL, REPETITIONS, +EASE (the \\='easiness factor\\='), FAILURES, MEANQ and TOTAL-REPEATS. +QUALITY is the rating just entered. Returns a list: (INTERVAL REPEATS EF FAILURES MEAN TOTAL-REPEATS OFMATRIX), where: @@ -1246,6 +1245,12 @@ Returns a list: - REPEATS is incremented by 1. - EF is modified based on the recall quality for the item. - OF-MATRIX is not modified." + (let ((last-interval (org-drill-card-state-last-interval state)) + (n (org-drill-card-state-repetitions state)) + (ef (org-drill-card-state-ease state)) + (failures (org-drill-card-state-failures state)) + (meanq (org-drill-card-state-meanq state)) + (total-repeats (org-drill-card-state-total-repeats state))) (if (zerop n) (setq n 1)) (if (null ef) (setq ef 2.5)) (setq meanq (if meanq @@ -1282,7 +1287,7 @@ Returns a list: (1+ n) next-ef failures meanq (1+ total-repeats) - org-drill-sm5-optimal-factor-matrix)))) + org-drill-sm5-optimal-factor-matrix))))) ;;; SM5 Algorithm ============================================================= (defun org-drill-modify-e-factor (ef quality) @@ -1520,13 +1525,7 @@ item will be scheduled exactly this many days into the future." (org-drill-card-state-failures state) (org-drill-card-state-meanq state) (org-drill-card-state-total-repeats state) ofmatrix)) - (sm2 (org-drill-determine-next-interval-sm2 - (org-drill-card-state-last-interval state) - (org-drill-card-state-repetitions state) - (org-drill-card-state-ease state) quality - (org-drill-card-state-failures state) - (org-drill-card-state-meanq state) - (org-drill-card-state-total-repeats state))) + (sm2 (org-drill-determine-next-interval-sm2 state quality)) (simple8 (org-drill-determine-next-interval-simple8 (org-drill-card-state-last-interval state) (org-drill-card-state-repetitions state) @@ -1590,13 +1589,7 @@ of QUALITY." (org-drill-card-state-meanq state) (org-drill-card-state-total-repeats state) org-drill-sm5-optimal-factor-matrix)) - (sm2 (org-drill-determine-next-interval-sm2 - (org-drill-card-state-last-interval state) - (org-drill-card-state-repetitions state) - (org-drill-card-state-ease state) quality - (org-drill-card-state-failures state) - (org-drill-card-state-meanq state) - (org-drill-card-state-total-repeats state))) + (sm2 (org-drill-determine-next-interval-sm2 state quality)) (simple8 (org-drill-determine-next-interval-simple8 (org-drill-card-state-last-interval state) (org-drill-card-state-repetitions state) |
