-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
function with loopy fails on second call #17
Comments
That is unexpected.
(defun mu4e:load-path-guix ()
"Return load-path for mu4e.
This assumes that you're on guix."
(let* ((base-dir "/tmp/mu4e-test/")
(regexp "\\`[[:alnum:]]+-mu-\\(?:[[:digit:]]\\|\\.\\)+"))
(let ((list-458 (directory-files base-dir))
(mu4e-path nil)
(full-path nil)
(file nil))
(cl-block nil
(while (consp list-458)
(setq file (car list-458))
(setq full-path (f-expand file base-dir))
(when (and (string-match-p regexp file)
(f-dir-p full-path))
(setq mu4e-path (f-expand "share/emacs/site-lisp/" full-path))
(when (f-dir-p mu4e-path)
(cl-return-from nil mu4e-path)))
(setq list-458 (cdr list-458)))
nil)))) EDIT: Also, what version of Emacs are you using? I tried creating a similar function (which expands to the above code) on Emacs 28, and it keeps returning |
I don't think this has to do with Guix or Mu4e. In my code I just search for a path that happens to be a path in guix and that happens to be for Mu4e. I tried reproducing with this for example. (defun mu4e:other-path ()
"Return load-path for mu4e.
This assumes that you're on guix."
(loopy (with (regexp "Documents")
(base-dir (f-full "~/")))
((list file (directory-files base-dir))
(expr full-path (f-expand file base-dir))))) Also I didn't repond to you immediately because i wanted to try it after
(emacs-version) ;;=>
"GNU Emacs 27.1 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.20, cairo version 1.16.0)"
No, it does not fail in that case. I post the code I evaluated. (defun mu4e:other-path ()
"Return load-path for mu4e.
This assumes that you're on guix."
(loopy (with (regexp "Documents")
(base-dir (f-full "~/")))
((list file (directory-files base-dir))
(expr full-path (f-expand file base-dir)))))
(mu4e:other-path)
;; second time produces an error
;; first time evaluated
nil (defun mu4e:other-path-macroexpanded ()
(let*
((base-dir
(f-full "~/"))
(regexp "Documents"))
(let
((full-path nil)
(file nil))
(let*
((list-45
(directory-files base-dir)))
(cl-block nil
(while
(consp list-45)
(setq file
(car list-45))
(setq full-path
(f-expand file base-dir))
(setq list-45
(cdr list-45)))
nil)))))
(mu4e:other-path-macroexpanded)
;; several calls to eval-print-last-sexp
nil
nil
nil
nil
I did not compile it. This is interpreted. |
I can reproduce this on Emacs 27.1, and will probably need to ask about this on the mailing list. Like what you found, if I evaluate the function in IELM, it will return The function value of the symbol (as gotten by (closure
(t)
nil "Return load-path for mu4e.
This assumes that you're on guix."
(loopy
(with
(regexp "Documents")
(base-dir
(f-full "~/")))
((list file
(directory-files base-dir))
(expr full-path
(f-expand file base-dir))))) after evaluating the function, but (closure
(t)
nil "Return load-path for mu4e.
This assumes that you're on guix."
(loopy
(with
(regexp "Documents"))
((list file
(directory-files base-dir))
(expr full-path
(f-expand file base-dir))))) after invoking the function. As you can see, |
I asked the question on the mailing list here: https://lists.gnu.org/archive/html/help-gnu-emacs/2021-02/msg00104.html. Below is the reply of Stefan Monnier:
In the current situation, the problem is:
which reverses the "with vars" received as arguments. This said, this
with
so that the subsequent I've made the change that he suggested, and the problem seems to be fixed. I still don't understand why it happens, or what is meant by the symbol's function value changing. I will write more when I get or am told more information. |
On a basic level I know that |
This problem was first reported in Issue #17, in which a bad ‘nreverse’ was somehow changing the function value of a symbol after evaluation.
Related to this experience is the discussion at https://old.reddit.com/r/emacs/comments/lf8whe/elisp_question_let_variables/, where a user notes that changes to a constant structure defined in a let-form persist between function calls. There, user wasamasa replies:
I would have thought that |
This seems to have been resolved, so I will close this. |
I wrote this function to begin automating finding the load-path of
mu4e
. Weird thing is that it succeeds on the first call (it returns a path), but on every call afterwards it throws an errorvoid-variable base-dir
.Notably when I just run the body of this function--aka the loopy loop--it always succeeds. I'm not sure exactly what's going on but i wanted to point this out.
This is the corresponding backtrace.
The text was updated successfully, but these errors were encountered: