<?xml version="1.0" encoding="windows-1252"?>
<node id="996383" title="Re: PERLISP meditations" created="2012-09-29 10:24:32" updated="2012-09-29 10:24:32">
<type id="11">
note</type>
<author id="708738">
LanX</author>
<data>
<field name="doctext">
Thats what you want?
&lt;c&gt;
my $sq = sub { $_[0]**2 };
my $id = sub { $_[0] };
 
sub sum {
  my ($a,$b,$func) =@_;
  $func //= $id;
  my $sum;
  $sum += $func-&gt;($_)  for ($a..$b);
  return $sum;
}
 
sub sum_sq{ sum($_[0],$_[1],$sq)}
 
$,=",";
print sum(3,5),sum_sq(3,5);	    # 12,50
&lt;/c&gt;&lt;P&gt;

I skipped the &amp;next sub for integer stepping, but shouldn't be to difficult with a while loop checking $a&lt;$b. &lt;P&gt;

(UPDATE: I'm puzzled... if "&amp;next" is necessary to get the next element of an iterator one must also provide a &amp;cmp for checking &lt;c&gt;$a&lt;$b&lt;/c&gt; in the loop-condition) &lt;P&gt;

Better avoid Lisp-recursion in Perl, when you can use "real" loops, we don't automatically optimize them to loops like Lisp does.&lt;P&gt;

&lt;!-- Node text goes above. Div tags should contain sig only --&gt;
&lt;div class="pmsig"&gt;&lt;div class="pmsig-708738"&gt;
&lt;p&gt;Cheers Rolf
&lt;/div&gt;&lt;/div&gt;</field>
<field name="root_node">
996373</field>
<field name="parent_node">
996373</field>
</data>
</node>
