[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: adding namespaces to emacs-lisp (better elisp?)
From: |
Drew Adams |
Subject: |
RE: adding namespaces to emacs-lisp (better elisp?) |
Date: |
Fri, 26 Jul 2013 15:00:03 -0700 (PDT) |
> > I am not wedded to the proposal of using the global obarray first. The
> > rules for interning are slightly more complicated in that case:
> > - given a string X
> > - lookup X in the local obarray
> > - if it exists return the symbol
> > - else
> > - lookup X in the global obarray
> > - if it exists return the symbol
> > - else
> > - add the symbol to the local obarray
>
> Exactly. In Mathematica, they have a list of obarrays to check in
> sequence and a "current" obarray to which things are added if the
> lookup fails. Sounds clean and simple to me.
And in Common Lisp (from CLTL, 1984 - didn't check CLTL2):
"When the Lisp reader has, by parsing, obtained a string of characters
thought to name a symbol, that name is looked up in the current package.
This lookup may involve looking in other packages whose external symbols
are inherited by the current package. If the name is found, the
corresponding symbol is returned. If the name is not found (that is,
there is no symbol of that name accessible in the current package), a
new symbol is created for it and is placed in the current package as an
internal symbol. Moreover, the current package becomes the owner (home
package) of the symbol, and so the symbol becomes interned in the current
package. If the name is later read again while this same package is
current, the same symbol will then be found and returned."
> > My feeling is that an import should be like the creation of an alias.
>
> Function alias? Variable alias?
> I don't much like the sounds of it. I'd much rather make sure they are
> simply one and the same symbol (I guess "symbol alias").
Yes.
In CL there are two different things, BTW:
* `import': Importing a symbol into a package. Importing makes the
symbol *present*, not just *accessible* in the importing package. If a
different symbol with the same name is already accessible in the
importing package then a user-correctable error is raised: `import'
avoids letting one symbol shadow another.
* `use-package': Inheriting a symbol, by using another package in which
it is external. The symbol becomes *accessible* as an internal symbol
in the using package. (There is no way to inherit the internal symbols
of a package.)
`use-package', unlike `import', does not cause any new symbols to be
present in the using package. It just makes them accessible by
inheritance.
A symbol is *accessible* in a package if it can be referred to without
a package qualifier when that package is current. A symbol is *present*
in a package if the name-to-symbol mapping (obarray entry) is in the
package itself and is not inherited. A symbol is interned in a given
package if (a) it is accessible there and (b) it is owned by some package
(i.e., it is interned somewhere).
`intern' causes a symbol to be interned in a package, like this:
"[I]t first looks for the symbol among the external and internal symbols
of the package itself [i.e., present there]; then it looks through the
external symbols of the used packages in some unspecified order. The
order does not matter; according to the rules for handling name conflicts
..., if conflicting symbols appear in two or more packages inherited by
package X, a symbol of this name must also appear [i.e., be present] in
X itself as a shadowing symbol."
"If the symbol was previously unowned, then the package it is interned
in becomes its owner (home package); but if the symbol was previously
owned by another package, that other package continues to own the
symbol."
FWIW, perhaps the most important part of the CL packages design are
these consistency rules:
"
* Read-read consistency: Reading the same print name always results in
the same (`eq') symbol.
* Print-read consistency: An interned symbol always prints as a sequence
of characters that, when read back in, yields the same (`eq') symbol.
* Print-print consistency: If two interned symbols are not `eq', then
their printed representations will be different sequences of characters.
"
- Re: adding namespaces to emacs-lisp (better elisp?), (continued)
- Re: adding namespaces to emacs-lisp (better elisp?), Nic Ferrier, 2013/07/26
- RE: adding namespaces to emacs-lisp (better elisp?), Drew Adams, 2013/07/26
- Re: adding namespaces to emacs-lisp (better elisp?), Stefan Monnier, 2013/07/26
- Re: adding namespaces to emacs-lisp (better elisp?), Nic Ferrier, 2013/07/26
- Re: adding namespaces to emacs-lisp (better elisp?), Stefan Monnier, 2013/07/26
- Re: adding namespaces to emacs-lisp (better elisp?), Nic Ferrier, 2013/07/27
- Re: adding namespaces to emacs-lisp (better elisp?), Stefan Monnier, 2013/07/27
- Re: adding namespaces to emacs-lisp (better elisp?), Nic Ferrier, 2013/07/27
- Re: adding namespaces to emacs-lisp (better elisp?), Stefan Monnier, 2013/07/27
- Re: adding namespaces to emacs-lisp (better elisp?), Pascal J. Bourguignon, 2013/07/27
- RE: adding namespaces to emacs-lisp (better elisp?),
Drew Adams <=
- Re: adding namespaces to emacs-lisp (better elisp?), Stefan Monnier, 2013/07/26
- RE: adding namespaces to emacs-lisp (better elisp?), Drew Adams, 2013/07/26
- Re: adding namespaces to emacs-lisp (better elisp?), Lars Brinkhoff, 2013/07/27
- Re: adding namespaces to emacs-lisp (better elisp?), Pascal J. Bourguignon, 2013/07/27
- Re: adding namespaces to emacs-lisp (better elisp?), Lars Brinkhoff, 2013/07/31
- Re: adding namespaces to emacs-lisp (better elisp?), Pascal J. Bourguignon, 2013/07/27
- Re: adding namespaces to emacs-lisp (better elisp?), Stefan Monnier, 2013/07/27
- RE: adding namespaces to emacs-lisp (better elisp?), Drew Adams, 2013/07/27
Re: adding namespaces to emacs-lisp (better elisp?), Davis Herring, 2013/07/26