develooper Front page | perl.perl5.porters | Postings from April 2003

Rindolfism: Namespaces

Thread Next
From:
Shlomi Fish
Date:
April 17, 2003 22:41
Subject:
Rindolfism: Namespaces
Message ID:
Pine.LNX.4.33L2.0304171939100.3918-100000@vipe.technion.ac.il

Hi!

This post is meant to bring some features that I'd like to see in perl 5
as part of the Rindolf specification.

1. The class MyClass { ... } construct

This construct decends one in namespace. E.g:

<<<
class MyClass
{
	class Other
	{
		sub hello
		{
			print "Hello\n";
		}
	}
}

MyClass::Other::hello();
>>>

will print hello. It is a bit more convenient at times than excessive use
of package with the same prefix over and over again. It is also similar to
the C++ namespace construct.

Note that from my impression this feature would be very easy to implement.
I don't think I should use a source filter because it's very hard to
match a balanced Perl code. Still, adding it at the lex and yacc level
should be quite easy, and coding the bit of logic for it, shouldn't be too
hard either.

2. Anonymous namespaces

This is actually a my $a = class { <CODE> }; where <CODE> contains any
Perl code similar to eval. It creates a first-order namespace inside $a.
Rindolf specifies two operators for it: extend and expand which are used
to extend an anonymous namespace with more constructs and variables and
dump a namespace into the current namespace. I don't mind they residing in
a separate namespace.

Namespaces and classes as first-order-values seems a bit hard to implement
in the current perl5 implementation. Can anyone outline what needs to be
done, and how we can break as little backwards compatibility as possible.

3. Meta-namespces: up and this

up is a namespace that goes up one in the package name: For instance:

<<<
package Data::Dumper::My;

my $var = "hello";
my $d = up->new([$var],['$var'])
>>>

This is similar to ".." in UNIX directories.

"this" starts at the current namespace and process downwards:

<<<
package Data;

my $var = "hello";
my $d = this::Dumper->new([$var],['$var'])
>>>

This change does not seem as something that would be very hard to
implement either. Can it pose a security breach, though?

Regards,

	Shlomi Fish


----------------------------------------------------------------------
Shlomi Fish        shlomif@vipe.technion.ac.il
Home Page:         http://t2.technion.ac.il/~shlomif/

An apple a day will keep a doctor away. Two apples a day will keep two
doctors away.

	Falk Fish




Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About