Prefer struct/set! to setf

I originally tried using `struct/set` instead of `setf`, which I had forgotten
was the *immutable* version of `struct/set!`. When this didn't work, I reverted
to `setf`. After a good night's sleep and with a fresh set of eyes, I dug into
the issue and discovered that `struct/set!` was what I wanted the whole.

I am curious now about `struct/update` versus `struct/update!`; shouldn't the
former be immutable and the latter be mutable? I'll save that investigation for
a later date.
This commit is contained in:
William Carroll 2020-01-09 13:38:51 +00:00
parent 5407eeb146
commit ef881e059b

View file

@ -27,6 +27,7 @@
(require 'maybe)
(require 'set)
(require 'cycle)
(require 'struct)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Library
@ -112,14 +113,18 @@ Return a reference to that buffer."
(if (> (ts-diff (ts-now) last-called)
buffer/source-code-timeout)
(progn
(setf (source-code-cycle-cycle buffer/source-code-cycle-state)
(cycle/from-list (buffer/source-code-buffers)))
(struct/set! source-code-cycle
cycle
(cycle/from-list (buffer/source-code-buffers))
buffer/source-code-cycle-state)
(let ((cycle (source-code-cycle-cycle
buffer/source-code-cycle-state)))
(funcall cycle-fn cycle)
(switch-to-buffer (cycle/current cycle)))
(setf (source-code-cycle-last-called buffer/source-code-cycle-state)
(ts-now)))
(struct/set! source-code-cycle
last-called
(ts-now)
buffer/source-code-cycle-state))
(progn
(funcall cycle-fn cycle)
(switch-to-buffer (cycle/current cycle))))))