Multmethods by arg-value

2002-12-10 Thread David Whipp
I was reading the Partially Memorized Functions thread, and the thought
came to mind that what we really need, is to define a different
implementation of the method for a specific value of the arg. Something
like:

sub days_in_month( Str $month, Int $year )
{
  ...
}

sub days_in_month( Str $month is value{ rx:i/feb[ruary]?/ }, Int $year ) is
cached
{
  ...
}


Dave.

--
Dave Whipp, Senior Verification Engineer,
Fast-Chip inc., 950 Kifer Rd, Sunnyvale, CA. 94086
tel: 408 523 8071; http://www.fast-chip.com
Opinions my own; statements of fact may be in error. 




Re: Multmethods by arg-value

2002-12-10 Thread Adam Turoff
On Tue, Dec 10, 2002 at 11:37:58AM -0800, David Whipp wrote:
 I was reading the Partially Memorized Functions thread, and the thought
 came to mind that what we really need, is to define a different
 implementation of the method for a specific value of the arg. Something
 like:
 
 sub days_in_month( Str $month, Int $year )
 {
   ...
 }
 
 sub days_in_month( Str $month is value{ rx:i/feb[ruary]?/ }, Int $year ) is
 cached
 {
   ...
 }

That strikes me as a lot of bugs waiting to happen.

What happens when you have multiple values that would match a given
parameter?

What happens when some module you don't even see loads a variant
of a sub you declare that matches some of the arguments you expected
to process?


XSLT has something similar.  The rules are subtle and easy to mess
up.  The XSLT spec also states that defining multiple subs (templates)
that could match a piece of input is an error, but may be resolved
by a specific algorithm (last definition prevails).  I'm not so
sure I like that behavior in Perl; it's all too easy to create new
subs at runtime...

Z.




Re: Multmethods by arg-value

2002-12-10 Thread Damian Conway
David Whipp wrote:


I was reading the Partially Memorized Functions thread, and the thought
came to mind that what we really need, is to define a different
implementation of the method for a specific value of the arg. Something
like:

sub days_in_month( Str $month is value{ rx:i/feb[ruary]?/ }, Int $year ) is
cached
{
  ...
}


Yes. I have raised this prospect with Larry. It's certainly a very powerful
capacity, and there are precedents in other languages. But, last I recall,
we were not certain that the advantages it would provide would outweigh the
complexities of implementation and usage that it would introduce.

Let's just say, we're still weighing our courage against our sanity on that
idea. ;-)

Damian