Malabarba / names

A Namespace implementation for Emacs-Lisp
250 stars 19 forks source link

Question about using namespace across multiple files? #15

Open melton1968 opened 9 years ago

melton1968 commented 9 years ago

If a namespace is split across multiple files (or even re-opening the namespace in the same file), is there a way to cause function names embedded inside a backquote to be namespace-ed? As an example, is there a way to write bmacro below other than fully specifying the function afunc?

(require 'names-dev)
(require 'names)

;; In file a.el
(define-namespace foo-bar-- :global

(defun afunc ()
  (message "foo-bar--afunc called"))

(afunc)  ; afunc called

(defun cfunc ()
  `(afunc))

(cfunc)
)

(provide 'foo-bar)

;; In file b.el
(define-namespace foo-bar-- :global

(defun bfunc ()
  (afunc))

(defmacro bmacro ()
  `(afunc))

(defmacro cmacro ()
  `(foo-bar--afunc))

(afunc)  ; afunc called
(bfunc)  ; afunc called
(bmacro) ; (void function afunc)
(cmacro) ; afunc called
)
Malabarba commented 9 years ago

This is a consequence of quoting, and it will happen regardless of how many files are used.

As a general and hard rule, anything quoted with a regular quote ' or a backtick (as in your example) is not namespaced. That's because quotes lists can be absolutely anything. There's no way of knowing whether it's a function form or some arbitrary data list.

The way you've written cmacro is the correct way of doing this. When you're inside a quote, you just need to specify the full name.

Still, there is a workaround for your case. Inside a backtick, forms preceded by a comma , are namespaced. So you should be able to do the following:

`(,#'afunc) 

But I still prefer the cmacro.

CestDiego commented 9 years ago

maybe this could make it in the doc? I want to start using namespacing on my packages :D I think names will be a good experiment.