Re: Woohoo! My macros are now (semi) hygienic
- From: Kaz Kylheku <kkylheku@xxxxxxxxx>
- Date: Mon, 25 Feb 2008 15:17:43 -0800 (PST)
On Feb 23, 8:50 am, Ron Garret <rNOSPA...@xxxxxxxxxxx> wrote:
In article
<31ee5725-d999-4306-9ce0-114e2e3fa...@xxxxxxxxxxxxxxxxxxxxxxxxxxx>,
"Leslie P. Polzer" <leslie.pol...@xxxxxxx> wrote:
Could you make up a quick comparison of what package problems it will
solve?
There are two main problems (or maybe I should call them annoyances)
with packages that Lexicons were designed to solve:
1. The need to manually build and maintain exported symbol lists
Automatically bringing together arbitrary symbols from different
namespaces into one scope is braindamaged. Only in rare situations
where the source namespace is very stable can you do a wholesale
import of its bindings without naming the specific names that you
want.
It sounds like you're basically reinventing something which has the
semantics of the Modula-2 WITH statement.
VAR foo : foo_record, bar : bar_record;
WITH foo DO
WITH bar DO
(* ... access members of bar and foo using short names ... *)
END;
END;
Above, there is also no need to maintain any export lists. Why?
Because all of the members of a record are considered ``exported''
under the WITH operator. When you add a new member to the record type
definition, it's automatically visible in all WITH statements which
involve that record type, everywhere in the program. Both foo_record
and bar_record each in fact constitute a lexicon where certain names
have bindings; these are instantiated in the instances instances foo
and bar. Thus WITH performs an import of these namespaces into the
current scope.
Suppose foo has a member x that you access in the DO block, and bar
doesn't have any member called x. So in that lexical scope, the name x
refers to foo.x. Suppose that someone now edits the type definition of
bar_record such that it acquires a member called x. Now when you
recompile the WITH statement above, the expression x suddenly refers
to bar.x! If bar.x is suitably typed, there will be no compiler
error. Unintentional shadowing of a local variable can also take
place: bad hygiene.
Modula-3 has a completely different WITH, a sane form which resembles
SYMBOL-MACROLET. The Modula-3 with creates lexical aliases for
expressions; only those names are introduced into the scope which are
explicitly listed in the WITH construct.
It's C++ that's carrying the torch now for the braindamaged WITH, in
the form of class scope.
int x;
int abc::foo()
{
// ``lexicon'' of abc class ``imported'' here.
return x + y; // y is abc::y, x is ::x.
}
If class is edited so that x is a member, now the expression returns
the member x. If you want the global x, you have to discover this
problem and then add the qualification ::x. You can also be clear that
you really want the member by writing this->x or abc::x.
Python and CL get this right; the object is passed explicitly, and you
write some expression that requests its member explicitly. No
automatic lexicon-munging.
The Common Lisp WITH-SLOTS is also sane, since you explicitly list the
bindings that you are importing.
.
- Follow-Ups:
- Re: Woohoo! My macros are now (semi) hygienic
- From: Marco Antoniotti
- Re: Woohoo! My macros are now (semi) hygienic
- From: Ron Garret
- Re: Woohoo! My macros are now (semi) hygienic
- From: Maciej Katafiasz
- Re: Woohoo! My macros are now (semi) hygienic
- References:
- Woohoo! My macros are now (semi) hygienic
- From: Ron Garret
- Re: Woohoo! My macros are now (semi) hygienic
- From: Kaz Kylheku
- Re: Woohoo! My macros are now (semi) hygienic
- From: Kent M Pitman
- Re: Woohoo! My macros are now (semi) hygienic
- From: Ron Garret
- Re: Woohoo! My macros are now (semi) hygienic
- From: Kent M Pitman
- Re: Woohoo! My macros are now (semi) hygienic
- From: Ron Garret
- Re: Woohoo! My macros are now (semi) hygienic
- From: Leslie P. Polzer
- Re: Woohoo! My macros are now (semi) hygienic
- From: Ron Garret
- Woohoo! My macros are now (semi) hygienic
- Prev by Date: Re: Document Cells for Noobsday
- Next by Date: Re: Woohoo! My macros are now (semi) hygienic
- Previous by thread: Re: Woohoo! My macros are now (semi) hygienic
- Next by thread: Re: Woohoo! My macros are now (semi) hygienic
- Index(es):
Relevant Pages
|