On Aug 14, 2010, at 6:23 PM, Steven C. Bagley wrote:

In R 2.11.1 on Mac OS 10.6.4, the following code works, but if the print statement is removed or commented out, then an infinite recursion results. Can someone explain what is going on? Thanks. -- Steve


foo2=function(f1, f2){
 print(f1)
 function(x){
   f1(x) + f2(x) } }

foo=function(...) Reduce(foo2, list(...))

foo(sin, cos, tan)(1)

?force

> foo2=function(f1, f2){
+  force(f1)
+  function(x){
+    f1(x) + f2(x) } }
>
> foo=function(...) Reduce(foo2, list(...))
>
> foo(sin, cos, tan)(1)
[1] 3.956286

--
David.

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to