all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Why I cannot use this variable in macro call from function?
@ 2021-06-08 13:10 Jean Louis
  2021-06-08 13:41 ` [External] : " Drew Adams
  0 siblings, 1 reply; 28+ messages in thread
From: Jean Louis @ 2021-06-08 13:10 UTC (permalink / raw)
  To: Help GNU Emacs

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/



^ permalink raw reply	[flat|nested] 28+ messages in thread

end of thread, other threads:[~2021-06-11  7:03 UTC | newest]

Thread overview: 28+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-06-08 13:10 Why I cannot use this variable in macro call from function? Jean Louis
2021-06-08 13:41 ` [External] : " Drew Adams
2021-06-08 14:47   ` Jean Louis
2021-06-08 17:14   ` Jean Louis
2021-06-08 18:31     ` tomas
2021-06-08 18:37       ` Oops function? tomas
2021-06-08 19:27       ` [SOLVED with `eval']: Why I cannot use this variable in macro call from function? Jean Louis
2021-06-08 20:03         ` tomas
2021-06-08 20:06           ` Sorry again tomas
2021-06-08 20:12           ` [SOLVED with `eval']: Why I cannot use this variable in macro call from function? Jean Louis
2021-06-08 20:23             ` tomas
2021-06-08 20:38               ` Jean Louis
2021-06-08 20:47               ` Jean Louis
2021-06-09  6:09                 ` tomas
2021-06-09  6:42                   ` Jean Louis
2021-06-09  6:51                     ` tomas
2021-06-09  7:03                       ` Jean Louis
2021-06-09  7:39                         ` tomas
2021-06-09  8:22                           ` Jean Louis
2021-06-09  8:54                             ` tomas
2021-06-09 10:56                               ` Jean Louis
2021-06-09 11:33                                 ` tomas
2021-06-09 14:39                                   ` Jean Louis
2021-06-09 16:41                                     ` tomas
2021-06-10  2:10                                     ` Robert Thorpe
2021-06-10  6:56                                       ` Jean Louis
2021-06-11  6:33                                         ` Robert Thorpe
2021-06-11  7:03                                           ` Jean Louis

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.