Your macro works fine. How did you try to invoke it? You should invoke like this: (make-my-function foo)
. Then M-: (symbol-function 'my-foo-function)
shows you the function definition:
(lambda nil
(interactive)
(message "It's work !"))
The reason that your initial attempt, before defining the macro, did not work is that defun
is a macro - it does not evaluate its arguments. So (defun (intern name) ())
is syntactically incorrect: defun
needs a symbol as its first argument, and (intern name)
is a list, not a symbol.
Updated, after your comment -
Your question is quite UNclear. Now it sounds like you want to call (make-my-function foo)
in a context where you have a variable my-foo-function
, whose value is a string.
If that's the case then use this:
(defmacro make-my-function (name)
(list 'defun
(intern (symbol-value (intern (format "my-%s-function" name))))
()
(list 'interactive)
'(message "It's work !")))
(setq my-foo-function "toto")
(make-my-function foo)
I cannot imagine such a use case, but I suspect that this too is not what you are trying to do. It does not seem like you have specified well what the required behavior is.