On 2009.04.23., at 22:18, John Cowan wrote:

>
> On Thu, Apr 23, 2009 at 12:52 PM, Jon Harrop <[email protected]>  
> wrote:
>
>>> http://neopythonic.blogspot.com/2009/04/tail-recursion-elimination.html
>> Not worth reading. Guido has absolutely no idea what he is talking  
>> about and
>> is probably the last person on Earth you should listen to in this  
>> context.
>
> I profoundly disagree.
>
> His points labeled "First" and "Second" are true: TCO does destroy
> stack trace information, and people would (and should) come to depend
> on TCO if it was available.

Yes, this can be a problem. I remember it was you who mentioned the  
call stack based security systems, and you're right, and Java security  
system is exactly of this kind...

For what's it worth (I keep referring to the example I'm familiar  
with) in Rhino it is possible to assign CodeSource to .js files and  
subject them to Java security policy, and in this scenario  
transitioning from caller to callee with a different CodeSource  
defeats TCO in interpreted mode.

Now, we couldn't even do it any differently no matter what we tried,  
since to effect a different CodeSource, we must call through a  
synthetic invoker thunk Java object, loaded through a synthetic  
SecureClassLoader that'll effect the new CodeSource on the Java stack.  
This naturally causes a JS->Java-JS transition (where "JS" means the  
stackless interpreter loop with TCO capabilities) so you can't have  
TCO in there.

Of course, the expectation is that most tail calls will happen between  
functions with the same CodeSource (trivially true for tail recursive  
functions, and also true for algorithms implemented by mutually  
recursive functions defined in the same source file) so TCO is not  
defeated in most cases, but still transitioning between different code  
sources will defeat it.

> [...]
>
> His final point (unnamed) correctly remarks that Python and C are
> generally intertwingled, and that since C does not have TCO, even a
> full Python implementation of TCO can still blow out the stack due to
> Python-C-Python-C recursion.  The same is true of at least some Scheme
> implementations with TCO, such as Chicken and Kawa.

Yes, same can happen in Rhino with JS-Java-JS-Java-... as explained  
above.

Attila.

--
twitter: http://twitter.com/szegedi
weblog: http://constc.blogspot.com

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "JVM 
Languages" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/jvm-languages?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to