This is the mail archive of the
kawa@sourceware.org
mailing list for the Kawa project.
Re: define-alias vs define-namespace?
- From: Per Bothner <per at bothner dot com>
- To: Yaroslav Kavenchuk <kavenchuk at gmail dot com>
- Cc: kawa <kawa at sourceware dot org>
- Date: Tue, 19 Feb 2008 18:14:16 -0800
- Subject: Re: define-alias vs define-namespace?
- References: <47BAF27F.6050305@gmail.com>
Yaroslav Kavenchuk wrote:
I read documentation. I found no difference in practice.
They cover overlapping functionality, but they're not
quite the same. You can use either to alias a class.
An "alias" is a "nickname":
(define-alias <SB> <java.lang.StringBuffer>)
You can use the nickname anywhere you can use the full name:
(make <SB>)
A "namespace" is a collection of names, and is not an alias in itself.
You can use a namespace for package/namespace management:
(define-namespace ns1 "foo")
(define-namespace ns2 "foo")
(define-namespace ns3 "bar")
(define ns1:x 12)
(define ns2:x ns1:x)
ns1:x and ns2:x are equivalent, because they're both aliases
(nicknames) for the same namespace, but ns1:x and ns3:x are
different.
You can alias any location, not just a class:
(define x 12)
(define-alias y x)
y ==> x
This doesn't work for define-namespace, because 12 isn't a namespace.
But when the 2nd operand is a class name, then define-namespace
and define-alias are pretty similar.
--
--Per Bothner
per@bothner.com http://per.bothner.com/