I\'m trying to create a function on the fly that would return one constant value.
In JavaScript and other modern imperative languages I would use closures:
;; -*- lexical-binding:t -*- (defun create-counter () (let ((c 0)) (lambda () (setq c (+ c 1)) c))) (setq counter (create-counter)) (funcall counter) ; => 1 (funcall counter) ; => 2 (funcall counter) ; => 3 ...