[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: Problem with shadow

>From: Jeff Dalton <jeff@aiai.edinburgh.ac.uk>
>Date: Mon, 20 Jan 92 12:30:30 GMT
>To: kcl@CLI.COM
>Subject: Problem with shadow
>Starting kcl ...
>In KCL there is a problem with shadowing.  Use-package still signals a
>name conflict error.  This is a bug.  Only an explicit import should
>signal an error for name conflict with a shadowing symbol.  (See CLtL
>II, section 11.5, page 255.)

Well, I am not sure whether this is a bug, but I agree with
Jeff in that SHADOWing a symbol that is already present in
the specified package should be put into the package-
shadowing-list.  To do this, replace the definition of
"shadow" in file c/package.d with the following code.

*** new code ***

shadow(s, p)
object s, p;
	int j;
	object *ip;

	find_symbol(s, p);
	if (intern_flag == INTERNAL || intern_flag == EXTERNAL) {
		if (!member_eq(s, p->p.p_shadowings))
			p->p.p_shadowings = make_cons(s, p->p.p_shadowings);
	} else {
		j = pack_hash(s);
		ip = &p->p.p_internal[j];
		vs_head->s.s_hpack = p;
		*ip = make_cons(vs_head, *ip);
		p->p.p_shadowings = make_cons(vs_head, p->p.p_shadowings);

*** end new code ***

Also, USE-PACKAGE must be modified.  The current USE-
PACKAGE signals an error if there is a symbol that is
present in the USEing package and that has the same name
as an external symbol in the USEd package.  This is because
symbols that are present in a package never appear in the
package-shadowing-symbols in that package, in current
implementation.  Replace the definition of "use_package"
in file c/print.d with the following code.

*** end new code ***

use_package(x0, p)
object x0, p;
	object x = x0;
	int i;
	object y, l;

	if (type_of(x) != t_package) {
		x = find_package(x);
		if (x == Cnil)
	if (x == keyword_package)
		FEerror("Cannot use keyword package.", 0);
	if (p == x)
	if (member_eq(x, p->p.p_uselist))
	for (i = 0;  i < PHTABSIZE;  i++)
		for (l = x->p.p_external[i];
		     type_of(l) == t_cons;
		     l = l->c.c_cdr) {
			y = find_symbol(l->c.c_car, p);
			if (intern_flag && l->c.c_car != y
			     && !member_eq(y, p->p.p_shadowings))
FEerror("Cannot use ~S~%\
from ~S,~%\
because ~S and ~S will cause~%\
a name conflict.", 4, x, p, l->c.c_car, y);
	p->p.p_uselist = make_cons(x, p->p.p_uselist);
	x->p.p_usedbylist = make_cons(p, x->p.p_usedbylist);

*** end new code ***

-- Taiichi