9 Jan 2013 sness   » (Journeyer)

JavaScript (ES6) Has Tail Call Optimization - A Passion for Breaking Things - Brandon Benvie does JavaScript

JavaScript (ES6) Has Tail Call Optimization - A Passion for Breaking Things - Brandon Benvie does JavaScript: "What is a Tail Call and Why Should I Care About Optimizing It?

A tail call is a function call who's return value is used as the caller's return value. Example:

function factorial(remaining, accumulator){
if (remaining === 0) {
return accumulator;
}
return factorial(remaining - 1, remaining * accumulator); // <--- tail call
}
Without tail call optimization, every recursive call will add another frame to the call stack, eventually leading to memory exhaustion. JavaScript engines typically will fail at 10,000 - 30,000 levels of recursion with a RangeError."

'via Blog this'

Syndicated 2013-01-09 18:23:00 from sness

Latest blog entries     Older blog entries

New Advogato Features

New HTML Parser: The long-awaited libxml2 based HTML parser code is live. It needs further work but already handles most markup better than the original parser.

Keep up with the latest Advogato features by reading the Advogato status blog.

If you're a C programmer with some spare time, take a look at the mod_virgule project page and help us with one of the tasks on the ToDo list!