develooper Front page | perl.perl6.language | Postings from January 2004

Re: A modest question

Thread Previous | Thread Next
Jonathan Lang
January 7, 2004 00:44
Re: A modest question
Message ID:
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

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About