Deep recursive functions

Started by
64 comments, last by Afaik 20 years, 6 months ago
quote:Original post by Sneftel
Yes it is,

No it isn''t. One can have side-effects in any impure language.

quote:because C++ is side-effect-happy. If C++ could do garbage collection, the example I cited would tail-recurse just fine.

The issue isn''t just GC; it''s the existance of destructors/finalizers. But, again, this isn''t unique to C++.


char a[99999],*p=a;int main(int c,char**V){char*v=c>0?1[V]:(char*)V;if(c>=0)for(;*v&&93!=*v;){62==*v&&++p||60==*v&&--p||43==*v&&++*p||45==*v&&--*p||44==*v&&(*p=getchar())||46==*v&&putchar(*p)||91==*v&&(*p&&main(0,(char**)(--v+2))||(v=(char*)main(-1,(char**)++v)-1));++v;}else for(c=1;c;c+=(91==*v)-(93==*v),++v);return(int)v;}  /*** drpizza@battleaxe.net ***/
Advertisement
quote:Original post by DrPizza
The issue isn''t just GC; it''s the existance of destructors/finalizers. But, again, this isn''t unique to C++.
No, it''s just GC. Finalizers don''t affect tail-recursion at all if their invocation doesn''t have to be at a particular line in the code; dependencies further down the stack will keep objects alive as long as they''re needed, and the GC will destroy them afterward.

How appropriate. You fight like a cow.
quote:Finalizers don''t affect tail-recursion at all if their invocation doesn''t have to be at a particular line in the code

"if". So, like I said, it''s not just GC. If your destructor did something such as print a message to the console to indicate that it was being destroyed (that whole "side-effects" thing again) then you''d still need to maintain a stack of the objects to be destroyed, so that the messages can be printed to the console in the correct order.
char a[99999],*p=a;int main(int c,char**V){char*v=c>0?1[V]:(char*)V;if(c>=0)for(;*v&&93!=*v;){62==*v&&++p||60==*v&&--p||43==*v&&++*p||45==*v&&--*p||44==*v&&(*p=getchar())||46==*v&&putchar(*p)||91==*v&&(*p&&main(0,(char**)(--v+2))||(v=(char*)main(-1,(char**)++v)-1));++v;}else for(c=1;c;c+=(91==*v)-(93==*v),++v);return(int)v;}  /*** drpizza@battleaxe.net ***/
quote:Original post by DrPizza
"if". So, like I said, it''s not just GC. If your destructor did something such as print a message to the console to indicate that it was being destroyed (that whole "side-effects" thing again) then you''d still need to maintain a stack of the objects to be destroyed, so that the messages can be printed to the console in the correct order.
Which is yet another example of C++''s feature set hindering this optimization. Languages with lazy or asynchronous GC prohibit programmers from expecting finalizers to run immediately, thus freeing up the compiler/interpreter to run them whenever is most convenient. By rigorously specifying object destruction time, in contrast, C++ limits itself to control flows that can properly respect these specifications.

How appropriate. You fight like a cow.
If you guys want to argue about GC or recursive functions or wahtver, make a thread for it. I think Afaik abandoned this thread a long time ago.
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
quote:Original post by DrPizza
It isn''t possible to eliminate them all (not least because C++ has no other way of performing I/O), but I certainly don''t use assignments often.

I''ll wager you modify member variables fairly often, and I reckon you''d find it a huge inconvenience if you couldn''t do so.

This topic is closed to new replies.

Advertisement