There are many (good) RFCs that specify new attributes.  To the best of my
knowledge, there is no good RFC discussing how to go about making
attributes, setting them, and getting them.

As far as setting|getting, I'd like to make a simple proposal.  Consider it
an idea for whoever writes the RFC (I'm looking at you, Nate) -- I don't
have the time to write or maintain an RFC.

The idea is this: every variable should have a psudohash of attributes.

To access the attribhash, you'd use somthing like this:
my($scalar,@array,%hash,^placeholder,&sub);
my %arraysattribs = %@array:;
my $subsline = $&sub:{line};

print "\%hash has the following attributes:\n";
foreach (keys %%hash:) {
        print "\$\%hash:{$_} = ", $%hash:{$_}, "\n";    
}

$subsattribsref = \%&sub:;

This is to say, the attribhash for a varable VAR (where VAR includes the
funny-character is the hash VAR:.  (You can use any expression with a valid
result for VAR.)

In 5.6, C<my $foo: = "42\n";> has the same effect as C<my $foo = "42\n";>,
and C<print $foo:;> is a syntax error.

You need to keep the funnychar of the attributed thingy somewhere in the
attribhash syntax, since otherwise $foo's attribues aren't seperable from
@foo's.

The reason you want an attribute hash is fairly obvious, I think.

An operator with rvalue and lvalue semantics is also possible:
%foosattribs = attribs @foo;
%foosattribs{private}++;
However, I can't see how you could set an attribue on a value without making
a temporary.

Variable names containing a : that isn't part of a :: would be reserved.
(That, or the bare colon is an operator returning a hash (not a list).)

You can also set an attribute like this:

my $foo :private;
This is equivlent to:
my $foo;
$$foo:{private} = 1;

my $foo :private(1);
is equivlent to
my $foo;
$$foo:{private} = [1];

my $foo;
means that
exists($$foo:{private}) is false.

You can put an attribute in anything that can be used as a variable:
Whole arrays.
Whole hashes.
Scalars.
Array elements.
Filehandles
[Globs].
Subs.
Hash values.
Hash key-value pairs?  This probably makes sense iff hash keys become full
scalars and not strings that act like scalars sometimes.  It would be
useful, though.

Note the last one especialy.

$$hash{elem}:{raccess}++;
$hash{elem} = 42;
exists $$hash{elem}:{raccess}; #is false.

This is because %$hash{elem}: sets the attribute on the value of
$hash{elem}, not on the spot in the hash.

I don't know what a good syntax for the hash position would be.  And I've
got other work to do now.

        -=- James Mastros




Creating attributes:



-- 
-----BEGIN GEEK CODE BLOCK-----
Version: 3.1
GU>CS d->-- s-:- a20 C++ UL+++@ P+++>+++++ L++@ E-() N o? K? w@ M-- !V
PS++ PE Y+ PGP(-) t++@ 5+ X+++ R+ tv+ b+++ DI+ D+ G e>++ h! r- y?
------END GEEK CODE BLOCK------

Reply via email to