Skip to content

Instantly share code, notes, and snippets.

@aaronfrost
Last active December 11, 2015 08:49
Show Gist options
  • Save aaronfrost/4576086 to your computer and use it in GitHub Desktop.
Save aaronfrost/4576086 to your computer and use it in GitHub Desktop.
Question for Dave Herman.
function foo(){
var temp = bar();
return temp;
}
/*
Is this a tail call? the call to bar is not actually in tail position, however
it is the last instruction to execute before the return expression. Let me know.
*/
@dherman
Copy link

dherman commented Jan 20, 2013

No, it's not a tail call. When people explain tail calls as "the last thing a function does" they're explaining the intuition but being imprecise. Proper tail calls are really about describing a syntactic category of positions known as tail position, and guaranteeing that the implementation uses a bounded amount of space for calls in tail position. Since, as you say, the call to bar in this example is not in tail position, it is not a tail call.

Dave

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment