This is the mail archive of the kawa@sourceware.org mailing list for the Kawa project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: define-alias vs define-namespace?


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/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]