In addition to what Lunanorne and Stefan said:
In the specific example you specified, funarg passed to fp-repeat does NOT really need the i variable.
That is, there is no need to do anything with i AS A VARIABLE. That is, it is not necessary to use i as a specific SYMBOL, the value of which should be determined at a certain time or in a specific context (environment), when and where the function is called.
This whole function is really needed by VALUE i when and where the function is defined. Using a variable in this particular case is redundant - only its value is required.
Thus, another way of flashing the needle is to replace the value of a variable in the definition of a function, i.e. in lambda expression:
(defun my-insert-stuff () (interactive) (dolist (i (list "1" "2" "3")) (fp-repeat 10 `(lambda () (insert ',i))) (insert "\n")))
It works great. There is no way to capture a variable because there is no variable.
The disadvantage is that during compilation there is also no function: LIST is created, car - lambda , etc. And this list is then evaluated at runtime, interpreted as a function.
Depending on the particular use case, this may be a useful method. Yes, that means you have to distinguish between contexts in which you really need to use a variable (that the function uses VARIABLE i , not just the value).
source share