> Subject: Re: [perl #78626] Patch: support higher arity in reduce()
> From: perl6-bugs-follo...@perl.org
> To: smosh...@hotmail.com
> Date: Thu, 28 Oct 2010 12:10:30 -0700
> 
> Patrick R. Michaud wrote:
> > On Wed, Oct 27, 2010 at 08:55:36PM -0700, Darren Duncan wrote:
> >> Stephen Mosher (via RT) wrote:
> >>> Attached is a diff against rakudo/src/core/Any-list.pm which adds support 
> >>> to
> >>> reduce() for higher-arity functions. It ensures arity-list agreement and 
> >>> is
> >>> generally safe. Other than the  test, the functionality was already
> >>> present... it  needed two lines commented out, two uncommented. Since 
> >>> tests
> >>> passed and there were no explanatory comments in the file, jnthn 
> >>> suggested I
> >>> mail in a diff. Here it is.
> >> What is a common or fundamentally important example of an N-adic
> >> function whose base operation takes 3 or more operands, such that
> >> reduce() would be useful?
> > 
> > At one point we had the higher-arity capability in reduce(), and then
> > took it out because it didn't seem to make much sense.  So, I agree with
> > Darren that we need to see a use case or example (or otherwise some
> > "approval" in the spec) before we restore this capability.
> 
> I can say that if the desire is to have reduce() wrap a function with 2 main 
> parameters (which the elements of the input list go to) plus 1..N extra 
> configuration parameters, then that can be handily dealt with by using a 
> curried 
> version of the base function that supplies the config params, so that then 
> there 
> are just 2 params left for reduce() to work with as usual.
> 
> While I throw that out there, I'm assuming that the higher-arity subject here 
> is 
> about taking 3 or more elements of the input list at once to feed the 
> function, 
> and its not about config params.
> 
> Do any meta-operator syntaxes let you define the base function inline such as 
> if 
> it would be a closure, or do they rightly only work for pre-defined symbols 
> and 
> you'd have to use a foo() format version of reduce for anything more 
> complicated?
> 
> -- Darren Duncan
> 
> 

Hi,

I was using it for a continued fraction reduction... something like 
(@array,0).reverse.reduce({$^c/($^b+$^a)}); where the fraction is not in 
...+1/x form. I would expect to run into other cases too.

Regards,
Stephen

                                          

Reply via email to