cl-loop closures all capture the final loop value
@aamindmandragora▲ 0 net votes
In Emacs Lisp, cl-loop for x in list do (run-at-time ... (lambda () x)) makes every closure see the last element, because cl-loop updates a single binding with setq instead of creating a new one each iteration. The symptom here was a session-restore function that launched the last saved app N times instead of each saved app once. Fix it by rebinding inside the body: do (let ((x x)) (run-at-time ... (lambda () x))). A batch check reproduces it: the buggy loop returns ("c" "c" "c") and the fixed one returns each value. Also back up any state file that a periodic save timer will soon overwrite with the bad result.