Newsgroups: perl.perl6.language Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!nntp.perl.org Return-Path: Mailing-List: contact perl6-language-h...@perl.org; run by ezmlm Delivered-To: mailing list perl6-langu...@perl.org Delivered-To: perl6-langu...@perl.org Message-ID: <20030408145220.35253.qmail@web12308.mail.yahoo.com> Date: Tue, 8 Apr 2003 07:52:20 -0700 (PDT) Reply-To: Austin_Hasti...@yahoo.com Subject: Re: Properties & Methods To: Luke Palmer , pdcaw...@bofh.org.uk Cc: perl6-langu...@perl.org In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-SMTPD: qpsmtpd/0.25, http://develooper.com/code/qpsmtpd/ X-Spam-Check-By: one.develooper.com X-Spam-Status: No, hits=-0.5 required=7.0 tests=CARRIAGE_RETURNS,IN_REP_TO,QUOTED_EMAIL_TEXT,SPAM_PHRASE_00_01 version=2.44 X-SMTPD: qpsmtpd/0.25, http://develooper.com/code/qpsmtpd/ Approved: n...@nntp.perl.org From: austin_hasti...@yahoo.com (Austin Hastings) References: Lines: 88 --- Luke Palmer wrote: > > In this case it would be great to have lexically and dynamically > scoped properties. So: > > sub breadth_first_traversal($root can LinksInterface, &code) { > my property visited; > # ... > } > > Or something, which would make the visited property a special one > that > is only visible in this invocation of the sub. Anybody else who > checks the visited property would see that it isn't set (unless they > had a different visited property). > Earlier on this list someone suggested that the only UML entity not well-represented in P6 so far is associations. This is evidence for that -- what is needed here is a way to tie the (relatively permanent) nodes to a (temporary) external item. Associations would do that. > Maybe properties are variables, independent of what they are attached > to. Then it would be possible to do all the neat scoping stuff we > can do with other variables. You could store references to > properties, and all that good stuff. > > =begin gross_speculation > > And then maybe they need sigils. Then we could use the dot notation: > > sub breadth_first_traversal($root can LinksInterface, &code) { > my ^visited; > # ... > unless $node.^visited > } > > (I had a choice of 3 sigils: >, |, and ^) You could use #, I think. my Property #include is sub { Perl6::Parse(::__interp, shift); } m4 anyone? > > return 0 but ^true; > > =end gross_speculation > > Or, we could make them typed scalars: > > sub breadth_first_traversal($root can LinksInterface, &code) { > my $visited = new Property; > # ... > unless $node.$visited > } > > I really like the scoped property idea, however it might be done. This *really* points to associations, since they would (obviously) die when the referenced object went out of scope. (Unless they didn't, in which case the object.DESTROY method should just automatically break any associations it has.) my $visited = new Association(...); sub breadth_first_traversal($root can LinksInterface, &code) { my $traversal = new Scalar(1); # Unique traversal id. if ($root has visited($traversal)) {...} else { $visited.relate($root, $traversal); } } This example is kind of weak because it suggests that associations can be implemented as a "pure" module -- I don't think they can because of (1) performance; and (2) behavior. I think that association behavior should be supported by the root of the object tree -- that is, if associations will be broken by Cing an object, then we need to make sure that the object tree does that, right at the top. =Austin