Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
object property syntax
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  6 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Todd W.  
View profile  
 More options Sep 25 2003, 4:48 am
Newsgroups: perl.perl6.language
From: t...@uakron.edu (Todd W.)
Date: Wed, 24 Sep 2003 19:53:39 -0400
Local: Wed, Sep 24 2003 7:53 pm
Subject: object property syntax
I have a question/request concerning perl6 object properties.

I've done some work with .NET and They have come up with a really slick way
to handle object properties.

A typical property definition in VB.NET looks like:

Public Property description() As String
  Get
    return aString
  End Get
  Set(ByVal Value As String)
    ' set value
  End Set
End Property

You can use it like this:

oObj.description = sDescr ' calls setter
sDescr = oObj.description ' calls getter

This allows proper encapsulation of object properties while providing a very
clean interface. A corollary feature is that properties can map to arbitrary
values. I've written object property definitions that read and write
directly to relational databases, and Ive written read only properties that
abstract XPath queries to config files.

My main interest in the feature is using the assignment operator to assign
to object properties.

I posted a question to CLPM on how to do this with perl5 and we decided to
use an 'lvalue' attribute on the subroutine and then make the returned
lvalue in the sub a tied variable to intercept read/writes:

http://groups.google.com/groups?th=5489106ee6715c8e

It works, but its obviously slow and can get confusing for anything
moderately complex.

I just thought I would share this and see if anything similar can fit in the
perl6 OO syntax.

Todd W.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Todd R Wade  
View profile  
 More options Sep 25 2003, 4:48 am
Newsgroups: perl.perl6.language
From: t...@uakron.edu (Todd R Wade)
Date: Thu, 25 Sep 2003 02:14:22 -0400 (EDT)
Local: Thurs, Sep 25 2003 2:14 am
Subject: object property syntax
I have a question/request concerning perl6 object properties.

I've done some work with .NET and They have come up with a really slick
way to handle object properties.

A typical property definition in VB.NET looks like:

Public Property propertyName() As String
  Get
    return aString
  End Get
  Set(ByVal Value As String)
    ' set value
  End Set
End Property

You can use it like this:

oObj.description = sDescr ' calls setter
sDescr = oObj.description ' calls getter

This allows proper encapsulation of object properties while providing a
very clean interface. A corollary feature is that properties can map to
arbitrary values. I've written object property definitions that read
and write directly to relational databases, and Ive written read only
properties that abstract XPath queries to config files.

My main interest in the feature is using the assignment operator to
assign to object properties.

I posted a question to CLPM on how to do this with perl5 and we decided
to use an 'lvalue' attribute on the subroutine and then make the
returned lvalue in the sub a tied variable to intercept read/writes:

http://groups.google.com/groups?th=5489106ee6715c8e

It works, but its obviously slow and can get confusing for anything
moderately complex.

I just thought I would share this and see if anything similar can fit
in the perl6 OO syntax.

Todd W.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Luke Palmer  
View profile  
 More options Sep 25 2003, 5:48 am
Newsgroups: perl.perl6.language
From: fibon...@babylonia.flatirons.org (Luke Palmer)
Date: Thu, 25 Sep 2003 02:58:33 -0600
Local: Thurs, Sep 25 2003 4:58 am
Subject: Re: object property syntax

Todd W. writes:
> I have a question/request concerning perl6 object properties.

Rather, attributes.  Properties are out-of-band data attached to a
particular object.

Okay, this has been thought through.  It's the way lvalue subs are going
to be pulled off in the more complex cases.  

I can't remember the exact syntax, but it goes something like:

    sub assign_to_me() is rw {
        my $ret is class { STORE { print "I was assigned to!\n" } }
    }

(Note that ret is both being created and returned in the same
expression)

Admittedly, that's a bit of a kludge, so there may be some syntax to
sugar it up.  I'd suggest an omitted C<do> property, with two additional
properties: C<fetch> and C<store>.

    sub assign_to_me() is rw
        will fetch { print "I was read from!\n" }
        will store { print "I was assigned to!\n" }
    {...}

Not to worry, as this is a nice thing to be able to do, it will be easy.

Luke


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Discussion subject changed to "object property syntax [OT]" by Matthijs Van Duin
Matthijs Van Duin  
View profile  
 More options Sep 25 2003, 5:48 am
Newsgroups: perl.perl6.language
From: p...@nubz.org (Matthijs Van Duin)
Date: Thu, 25 Sep 2003 11:41:08 +0200
Local: Thurs, Sep 25 2003 5:41 am
Subject: Re: object property syntax [OT]

On Wed, Sep 24, 2003 at 07:53:39PM -0400, Todd W. wrote:
>I posted a question to CLPM on how to do this with perl5 and we decided to
>use an 'lvalue' attribute on the subroutine and then make the returned
>lvalue in the sub a tied variable to intercept read/writes:

>http://groups.google.com/groups?th=5489106ee6715c8e

Note that this has already kinda been done:

http://search.cpan.org/~juerd/Attribute-Property-1.04/Property.pm

This only does setter-code (the getter always uses an element of the object)
but it's perhaps interesting to look at.

>It works, but its obviously slow

A::P uses the 'Want' module (if installed) to speed up the common cases.

--
Matthijs van Duin  --  May the Forth be with you!


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Discussion subject changed to "object property syntax" by Dan Sugalski
Dan Sugalski  
View profile  
 More options Sep 25 2003, 10:48 am
Newsgroups: perl.perl6.language
From: d...@sidhe.org (Dan Sugalski)
Date: Thu, 25 Sep 2003 09:58:33 -0400 (EDT)
Local: Thurs, Sep 25 2003 9:58 am
Subject: Re: object property syntax

Perl 6 will do something similar. Attributes (aka slot variables, aka
properties, aka "those thingies in the object") will, if you tell perl,
automatically get an lvalue method of the same name created for them. So
if you have a class that looks like (Excuse the syntax, I'm an internals
guy):

  class Foo {
    my $.attr1 is rw;
  }

and an object of class Foo:

  my Foo $bar;

then you can read and write that attribute with code like:

  $bar.attr1 = "fooey";
  print $bar.attr1, " to you!";

This has the nice property of allowing you to override the access to the
attribute if you want by defining an lvalue method with the same name as
the attribute, in which case that method will be called instead.

                                Dan


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Dan Sugalski  
View profile  
 More options Sep 25 2003, 10:48 am
Newsgroups: perl.perl6.language
From: d...@sidhe.org (Dan Sugalski)
Date: Thu, 25 Sep 2003 09:53:59 -0400 (EDT)
Local: Thurs, Sep 25 2003 9:53 am
Subject: Re: object property syntax

On Thu, 25 Sep 2003, Luke Palmer wrote:
> Todd W. writes:
> > I have a question/request concerning perl6 object properties.

> Rather, attributes.  Properties are out-of-band data attached to a
> particular object.

FWIW, "attribute" and "property" are two words that have a meaning that
shifts depending on what language you're talking about. IIRC, .NET
languages have them exactly reversed from perl 6's usage...

                                Dan


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »