1

I'm working on two general functions for executing independent unit-tests in elisp. One is about doing something and reset all custom-variables of my package, the other is about doing something in a temp-buffer and reset all custom-variables of my package.

Function (general):

(defun package-test-test (func)
    ""
    (unwind-protect
        (funcall func)
      (reset-all-custom-package-variables)))

Function (temp-buffer):

    (defun package-test-test-in-buffer (func)
        ""
        (package-test-test
            (lambda ()
                (with-temp-buffer (funcall func)))))

When i now call: (package-test-test-in-buffer (lambda () (insert "a"))) it exceeds max-lisp-eval-depth, why (there is no recursion)?

lordnik22
  • 48
  • 1
  • 8
  • Please enable `debug-on-error` in the options menu and examine the `*Backtrace*` buffer. – sds Oct 31 '17 at 13:19
  • It looks like that it is not allowed two have the same parameter name when calling them later as functions. – lordnik22 Oct 31 '17 at 15:28
  • Well you're *allowed* to (hence the symptom of your problem), but what's *happening* is that `package-test-test` binds the variable `func` to a function which itself evals `(funcall func)`, and then it calls that function. Hence the infinite recursion. – phils Nov 01 '17 at 05:31

1 Answers1

3

Your problem is the dynamic binding which is the default in Emacs Lisp: func arguments in your functions are the same variable. You need to rename one of them or use lexical binding.

See also How to live with Emacs Lisp dynamic scoping?

sds
  • 58,617
  • 29
  • 161
  • 278