Reputation: 33
(defun foo (aa)
(interactive)
(progn
(setq aa '(+ aa 1))
))
(defun bar ()
(interactive)
(setq b 6)
(add-hook 'post-self-insert-hook (foo b)))
Instead of incrementing b
, elisp throws an error: Invalid function: 7
. It does take b
as an argument, but only when its equal to 6, it stops working after incrementing. Why? The problem occures with b
being equal to any number, it always prints message like Invalid function:b+1
.
Upvotes: 0
Views: 142
Reputation: 73314
As sds says, there are a lot of problems with that code.
(defun foo (aa)
(interactive)
(progn
(setq aa '(+ aa 1))
))
This function briefly sets the variable aa
(which is its own argument and never seen by anything outside of the function) to the literal quoted form (+ aa 1)
. It also returns that same value. Here aa
is the symbol aa
and nothing more.
(defun bar ()
(interactive)
(setq b 6)
(add-hook 'post-self-insert-hook (foo b)))
(foo b)
is not a function, and therefore adding it to a hook will result in an error.
(lambda () (foo b))
is a function which calls (foo b)
elisp throws an error: Invalid function: 7.
Not with the code you've shown, it won't. Clearly you're evaluating a version in which you haven't quoted (+ aa 1)
in which case (foo 6)
will actually return 7
and hence you're trying to do this:
(add-hook 'post-self-insert-hook 7)
Upvotes: 0
Reputation: 60044
Right now there are far too many problems with your code to address them one by one.
You need to start with learning how Lisp works.
In Emacs, hit C-h i then click on Emacs Lisp Intro: (eintr), then keep reading.
Upvotes: 1