Properties

2003-11-27 Thread Luke Palmer
Here's a series of questions/confirmation requests about how properties
work (but specifically run-time properties, not traits):

Use Cbut to assign a property to a Ivalue:

$a = $b but foo;   # $a has property foo, $b does not

Properties are just out-of-band methods:

if $x.foo { print $x has property foo }
$x.bar = 1;   # Or $x = $x but bar

Which makes meta-properties (eg. Cnothing) easy to fathom.

(That one seems a little dangerous from an error checking point of view.
Is there such thing as a 'method not found' error?)

To get a hash of out-of-band properties, use either the Cbtw or the
Cprops method, depending on whether our language designers are feeling
cute.

Luke


Re: 'Core' Language Philosophy [was: Re: 'catch' statement modifier]

2003-11-27 Thread Michael G Schwern
On Wed, Nov 26, 2003 at 03:56:28PM -0500, Mark J. Reed wrote:
 Nicer it may be, But I use File::Find *because* it's in the core,
 so I don't have to worry about my programs being non-portable because I
 use a module that may not be installed.  

Of course with Perl 6 modules will be MUCH easier to install. :)


-- 
Michael G Schwern[EMAIL PROTECTED]  http://www.pobox.com/~schwern/
Cottleston, Cottleston, Cottleston Pie.
A fly can't bird, but a bird can fly.
Ask me a riddle and I reply:
Cottleston, Cottleston, Cottleston Pie.


Re: Properties

2003-11-27 Thread Larry Wall
On Thu, Nov 27, 2003 at 12:02:30AM -0700, Luke Palmer wrote:
: Here's a series of questions/confirmation requests about how properties
: work (but specifically run-time properties, not traits):
: 
: Use Cbut to assign a property to a Ivalue:
: 
: $a = $b but foo;   # $a has property foo, $b does not

That is correct.

: Properties are just out-of-band methods:

I had been thinking of the value as an object of a singleton class
that has an extra method.  In other words, properties would merely be
mixins.  But that would imply that the property hides any real method
of the same name.  On the other hand, it would be nice to be able to
promote an inert property to an active method.  But I think that has
to be done on purpose, not by accidentally having a method of the same
name.  So I suspect it needs to be an error to have a name collision
between a property and a method unless the method specifically says
that it's emulating a property.  This will fit it more with Perl 6's
idea of how to compose classes,  We won't be doing mixins--we'll be
doing something better.  It resembles something in the literature
called Traits, but we're generalizing that, and calling it roles.
(Oh, apparently C# 2.0 is thinking along the same lines with its
partial classes, though I haven't looked at those in detail.)

A role is like a chunk of class that can be incorporated into other
classes.  It's a bit like mixins, but it's safer than mixins because
it detects name collisions at class composition time.  There's also a
resemblence to generics, insofar as a role is at least parameterized on
its super class, since a given role can be incorporated into different
classes.  (And if a role can be parameterized on one class, there's no
reason in principle it can't be parameterized on multiple classes.)

The basic underlying philosophy is that classes should not be used
both to create objects and to specify the scope of reusable code.
At least, they should not be forced to do both of those.  So I think
Perl 6 will attempt to divorce those concerns.

Needless to say, Apocalypse 12 will talk a lot more about roles.
But let me just say that I'm currently thinking of a property as a
funny role composed into a singleton class.  As a role composition,
we get control over any name collisions.

: if $x.foo { print $x has property foo }
: $x.bar = 1;   # Or $x = $x but bar

Or maybe the .bar notation is only for rvalues, and to create a
property you have to say:

$x but= bar;

: Which makes meta-properties (eg. Cnothing) easy to fathom.

That would certainly be easy to do under a role-playing implementation.

: (That one seems a little dangerous from an error checking point of view.
: Is there such thing as a 'method not found' error?)

Certainly, as long as we limit the .bar notation to rvalues or to
lvalues on already-created properties.  And 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.

: To get a hash of out-of-band properties, use either the Cbtw or the
: Cprops method, depending on whether our language designers are feeling
: cute.

The feeling of this language designer at this moment is that
properties aren't kept in a hash.  They're indistiguishable from
other attributes/methods except insofar as they are composed into the
singleton class from roles that happen to be marked as property roles.
If we have a .props or .btw method of accessing that set of methods,
it's just syntactic sugar for ordinary method introspection with a
funny selection criterion.

Now it's certainly possible that non-active properties will be
optimized to a hash of non-active values internally, but we shouldn't
really think of them that way.  We should think of them as methods
of a singleton class, or more precisely, of a role that cuts across
a number of singleton classes.  In that respect it's a bit like
aspect-oriented programming, only it happens conceptually at compile
time, without having to write a bunch of method wrappers.

Larry

P.S. I think we deserve a $rubyometer-- for bypassing mixins.


Re: Properties

2003-11-27 Thread Simon Cozens
[EMAIL PROTECTED] (Larry Wall) writes:
 P.S. I think we deserve a $rubyometer-- for bypassing mixins.

I think you deserve loud and wild applause for an object model I want
to use Right Now Dammit.

-- 
Overall there is a smell of fried onions.  (fnord)


Re: Properties

2003-11-27 Thread Paul Hodges

--- 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?


__
Do you Yahoo!?
Free Pop-Up Blocker - Get it now
http://companion.yahoo.com/


Re: Properties

2003-11-27 Thread Larry Wall
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;
}

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.
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;

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.
Or maybe we can tag property names with the scope in which they're
declared somehow.

Larry