Front page | perl.perl6.language |
Postings from January 2004
Re: A modest question
Thread Previous
|
Thread Next
From:
Jonathan Lang
Date:
January 7, 2004 00:44
Subject:
Re: A modest question
Message ID:
20040107084356.59312.qmail@web40812.mail.yahoo.com
Piers Cawley wrote:
> > Why does it have to be a String, though? What prevents it from
> > working with anything that can stringify, besides the overly
> > restrictive signature? What if you could say (the Perl 6 equivalent
> > of):
> >
> > sub print_it ( does Stringify $thingie )
> > {
> > print $thingie.stringify();
> > }
> >
> > That's both more general and something more specific. By asking for
> > what you really want, you're not coding everyone else into a corner.
>
> In this particular case I prefer the Smalltalk thing of requiring all
> objects to have a C<print_on($aStream)> method and not even requiring
> that C<$aStream> satisfy the Stream role. But that's probably a matter
> of taste.
Maybe as an alternative to
role Stringify {must stringify();}
sub print_it (Stringify $thingie) {print $thingie.stringify();}
you might be able to say
sub print_it ($thingie must stringify()) {print $thingie.stringify();}
Hmm... there's a certain elegance to being able to specify one or two
requirements directly in a signature.
Also: in the first of these two, would classof($thingie) actually have to
have Stringify as a role, or would it be reasonable to instead say that
classof($thingie) must meet Stringify's demands? The latter would require
more work on the compiler's part, but would be considerably more flexible.
Perhaps "Stringify $thingie" requires that the Stringify role must
actually be used, while something like "$thingie like Stringify" would
only require that Stringify's demands be met?
=====
Jonathan "Dataweaver" Lang
__________________________________
Do you Yahoo!?
Yahoo! Hotjobs: Enter the "Signing Bonus" Sweepstakes
http://hotjobs.sweepstakes.yahoo.com/signingbonus
Thread Previous
|
Thread Next