[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Why I cannot use this variable in macro call from function?
From: |
Jean Louis |
Subject: |
Why I cannot use this variable in macro call from function? |
Date: |
Tue, 08 Jun 2021 16:10:54 +0300 |
I have this macro, as purpose of it is to dynamically generate history
variables for more than 100 database tables. If new database table is
generated a new variable will be generated without changing the source
code.
(defmacro rcd-db-completing-table-history (table)
(let ((variable (intern (concat "rcd-db-completing-table-history-" table))))
`(if (boundp ,variable)
(quote ,variable)
(progn
(defvar ,variable nil ,(format "History for table `%s'" table))
(quote ,variable)))))
The above macro expands into following:
(macroexpand '(rcd-db-completing-table-history "var-name")) ⇒ (if (boundp
rcd-db-completing-table-history-var-name)
'rcd-db-completing-table-history-var-name (progn (defvar
rcd-db-completing-table-history-var-name nil "History for table `var-name'")
'rcd-db-completing-table-history-var-name))
As I need a symbol for completing read and mini buffer functions.
However, here are the problems:
If I press C-M-x in the middle of the following function, the function
will be defined without erorr. If I press C-x C-e on the end I will
get debugging error: sequencep, var
Here I cannot understand why I cannot use `var' variable to call macro
from a function?
(defun my-fun-123 ()
(let ((var "new"))
(rcd-db-completing-table-history var)))
(my-fun-123)
Debugger entered--Lisp error: (wrong-type-argument sequencep var)
concat("rcd-db-completing-table-history-" var)
(intern (concat "rcd-db-completing-table-history-" table))
(let ((variable (intern (concat "rcd-db-completing-table-history-" table))))
(list 'if (list 'boundp variable) (list 'quote variable) (list 'progn (list
'defvar variable nil (format "History for table `%s'" table)) (list 'quote
variable))))
(closure (t) (table) (let ((variable (intern (concat
"rcd-db-completing-table-history-" table)))) (list 'if (list 'boundp variable)
(list 'quote variable) (list 'progn (list 'defvar variable nil (format "History
for table `%s'" table)) (list 'quote variable)))))(var)
(rcd-db-completing-table-history var)
(let ((var "new")) (rcd-db-completing-table-history var))
my-fun-123()
(progn (my-fun-123))
eval((progn (my-fun-123)) t)
elisp--eval-last-sexp(nil)
eval-last-sexp(nil)
funcall-interactively(eval-last-sexp nil)
call-interactively(eval-last-sexp nil nil)
command-execute(eval-last-sexp)
Jean
Take action in Free Software Foundation campaigns:
https://www.fsf.org/campaigns
In support of Richard M. Stallman
https://stallmansupport.org/
- Why I cannot use this variable in macro call from function?,
Jean Louis <=
- RE: [External] : Why I cannot use this variable in macro call from function?, Drew Adams, 2021/06/08
- Re: [External] : Why I cannot use this variable in macro call from function?, Jean Louis, 2021/06/08
- Re: [External] : Why I cannot use this variable in macro call from function?, Jean Louis, 2021/06/08
- Re: [External] : Why I cannot use this variable in macro call from function?, tomas, 2021/06/08
- Oops function?, tomas, 2021/06/08
- [SOLVED with `eval']: Why I cannot use this variable in macro call from function?, Jean Louis, 2021/06/08
- Re: [SOLVED with `eval']: Why I cannot use this variable in macro call from function?, tomas, 2021/06/08
- Sorry again, tomas, 2021/06/08
- Re: [SOLVED with `eval']: Why I cannot use this variable in macro call from function?, Jean Louis, 2021/06/08
- Re: [SOLVED with `eval']: Why I cannot use this variable in macro call from function?, tomas, 2021/06/08