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
Message from discussion Roles and Mix-ins?

Newsgroups: perl.perl6.language
Path: archiver1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed.stanford.edu!nntp.perl.org
Return-Path: <fibon...@babylonia.flatirons.org>
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
Date: Tue, 6 Jan 2004 02:51:27 -0700
To: perl6-langu...@perl.org
Subject: Re: Roles and Mix-ins?
Message-ID: <20040106095127.GA17281@babylonia.flatirons.org>
References: <000401c3c10e$bbda88b0$919a5718@borg> <20031213115717.GB20225@babylonia.flatirons.org> <20031213191230.GA18685@wall.org> <20040105164608.GA69309@megazone.bigpanda.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Disposition: inline
In-Reply-To: <20040105164608.GA69309@megazone.bigpanda.com>
User-Agent: Mutt/1.5.4i-ja.1
X-Spam-Check-By: la.mx.develooper.com
X-Spam-Status: No, hits=-2.7 required=7.0 tests=CARRIAGE_RETURNS,IN_REP_TO,QUOTED_EMAIL_TEXT,REFERENCES,SPAM_PHRASE_00_01,USER_AGENT,USER_AGENT_MUTT version=2.44
X-SMTPD: qpsmtpd/0.26, http://develooper.com/code/qpsmtpd/
Approved: n...@nntp.perl.org
From: fibon...@babylonia.flatirons.org (Luke Palmer)
Lines: 49

David Storrs writes:
> 
> On Sat, Dec 13, 2003 at 11:12:31AM -0800, Larry Wall wrote:
> > On Sat, Dec 13, 2003 at 04:57:17AM -0700, Luke Palmer wrote:
> 
> > : For one, one role's methods don't silently override another's.  Instead,
> > : you get, er, role conflict and you have to disambiguate yourself.  
> 
> How do you disambiguate?

Let's see...

    role Dog {
        method bark() { print "Ruff!" }
    }
    role Tree {
        method bark() { print "Rough!" }
    }
    class Trog 
      does Dog does Tree {
        method bark() { .Dog::bark() }
      }
    }

Perhaps something like that.  In any case, you do it by putting the
offending method directly in the aggregating class.

> After reading this several times, I _think_ I understand.  Let me
> check: imagine that the original class is a text buffer going from
> 0-99.  We have two roles (A and B), each of length 100.  Objects of
> various types can then see different segments of the buffer (i.e.,
> different methods/properties/whatever), as follows:
> 
> 	Type		Can see 
> 	----		-------
> 	Class		1-100		
> 	A		101-199
> 	B		200-299
> 	Class+A		1-100,101-199
> 	Class+B		1-100,200-299
> 	Class+A+B	1-100,101-199,200-299
> 
> Is that right?

Umm... I'm not sure that's what I'd use roles for.  And I'm not sure how
roles with associated data are supposed to work yet.  But I think you
have the general idea.

Luke