unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* [newbie] trouble getting the context of macros
@ 2020-02-02 11:03 Marco Maggi
  2020-02-02 16:20 ` Drew Adams
  0 siblings, 1 reply; 2+ messages in thread
From: Marco Maggi @ 2020-02-02 11:03 UTC (permalink / raw)
  To: help-gnu-emacs

Ciao,

  under Emacs 26 I'm trying to learn how to define macros.  This is a
session in the *scratch* buffer:

(defmacro my-try (op)
  `(defun ,op (op1 op1) t))
my-try
(my-try fun1)
fun1
(fun1 1 2)
t

fine, now this:

(defmacro my-try-2 (op)
  (let ((fun (make-symbol (concat "my-" (symbol-name op)))))
    `(defun ,fun (op1 op1) t)))
my-try-2
(my-try-2 fun3)
my-fun3
(my-fun3 1 2)

the last form gives me the error "eval: Symbol’s function definition is
void: my-fun3".  I do not understand why.

TIA
-- 
Marco Maggi


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

* RE: [newbie] trouble getting the context of macros
  2020-02-02 11:03 [newbie] trouble getting the context of macros Marco Maggi
@ 2020-02-02 16:20 ` Drew Adams
  0 siblings, 0 replies; 2+ messages in thread
From: Drew Adams @ 2020-02-02 16:20 UTC (permalink / raw)
  To: Marco Maggi, help-gnu-emacs

> (defmacro my-try-2 (op)
>   (let ((fun (make-symbol (concat "my-" (symbol-name op)))))
>     `(defun ,fun (op1 op1) t)))
> my-try-2
> (my-try-2 fun3)
> my-fun3
> (my-fun3 1 2)
> 
> the last form gives me the error "eval: Symbol’s function definition is
> void: my-fun3".  I do not understand why.

Try this instead:

(defmacro my-try-2 (op)
  (let ((fun  (intern (concat "my-" (symbol-name op)))))
    `(defun ,fun (op1 op2) t)))

`C-h f make-symbol' tells you that the new symbol
it returns is not interned.

See the Elisp manual, node Creating Symbols, for
info about `intern' and `make-symbol'.

https://www.gnu.org/software/emacs/manual/html_node/elisp/Creating-Symbols.html



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

end of thread, other threads:[~2020-02-02 16:20 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-02-02 11:03 [newbie] trouble getting the context of macros Marco Maggi
2020-02-02 16:20 ` Drew Adams

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).