--- Larry Wall <[EMAIL PROTECTED]> wrote:
> On Thu, Nov 27, 2003 at 08:08:05PM -0800, Paul Hodges wrote:
> : --- Larry Wall <[EMAIL PROTECTED]> wrote:
> : > ... in fact, we may be limiting the creation of properties
> : > to predeclared names, so that even
> : >
> : > return 0 but ture;
> : >
> : > can be caught at compile time.
> :
> : Excellent, so long as we can define new properties explicitly.
> : At the moment, I draw a complete blank on how to do that.
> :
> : Somebody drop me an example?
>
> Well, it hasn't been defined yet. Likely there will be some syntax
>
> my property foo;
>
> that is shorthand for something vaguely resembling
>
> my role foo is property {
> has $.foo is rw;
> }
That's cool. You might even consider making declarable properties a
little *less* convenient, though.... Of course, I bet you *have*
considered it, lol.
> However, universal properties like "true" and "tainted" are likely to
> be declared implicitly everywhere:
>
> property *true;
> property *tainted;
>
> Less common properties are likely to be imported into a lexical
> scope.
hmm... lexical properties....I've read the rest of the message, and I
see how this could be a problem. Just to be clear on it, what exactly
would it mean for a property or trait to be lexical? If a value or
container with that aspect gets passed out of that scope, what happens?
Wouldn't an object efectively provide a virtual "scope" of its own?
> So you'd likely only declare properties that you use entirely by
> yourself, or that you intend to export. If you really want to mess
> everyone up, though, you could certainly declare things like:
>
> property *ture;
And I can certainly see someone doing just that.
False laziness, false impatience, false hubris.... :)
> Actually, there's something to be said for declaring all property
> names as globals, since they cut across object classes, and you
> wouldn't want to add two different properties of the same name to
> a given object.
Agreed.
Maybe the syntax looks something like this:
class Foo has Scalar bar is rw = undef; # suplies a default value;
That would allow you to add the property to the class with a default
value at compile time, wouldn't it? Then you could modify objects:
my $o = Foo.new;
$o.foo but= "stuff";
It would also make it inherently class scoped, and would fail to
compile if someone in another module had already declared a property
bar. Right?
> Or maybe we can tag property names with the scope in which they're
> declared somehow.
o. That's hairy, isn't it?
Yes, I think it would be useful...but what's the upshot? The value of
$o.foo is dependent on scope? Hmm.... My first reaction was to frown
and shudder, but maybe that's short-sighted. Any lexical variable's
value is always dependent on scope.
our $foo = 1;
{ my $foo = 2;
print $foo; # 2
}
print $foo; # 1
I'm just not sure how I like the idea of that applying to properties.
our $o = Foo.new();
$o.foo but= "global?";
dostuff::with($o); # module scope, different value?
Wouldn't that utterly mangle the principle of least surprise?
> Larry
__________________________________
Do you Yahoo!?
Free Pop-Up Blocker - Get it now
http://companion.yahoo.com/