[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

avoid global variables by using closures

From: Emanuel Berg
Subject: avoid global variables by using closures
Date: Wed, 08 Sep 2021 22:07:58 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

I don't know what I've been smoking, this gave me a warning
from the byte-compiler saying the function wasn't known to be
defined, but now it seems to work all of a sudden?

(require 'cl-lib)

(let ((times 0))
  (defun time (&optional reset)
    (let ((res (or reset current-prefix-arg)))
      (if res
          (setq times 0)
        (cl-incf times) ))
    (if (called-interactively-p 'interactive)
        (message "times: %d" times)
      times) ))
;; test:
;;   (call-interactively 'time)
;;   (let ((current-prefix-arg t)) (call-interactively 'time))
;;   (time)
;;   (time t)

underground experts united

reply via email to

[Prev in Thread] Current Thread [Next in Thread]