Version 3 of ::tcl::unsupported::tailcall

Updated 2008-07-13 17:45:41 by miguel

Experimental command provided by NRE, available in HEAD and onwards from the release of Tcl8.6a2.

The command provides proper tailcalls, with the following semantics:

  • a proc/lambda invokes [tailcall foo [bar] $soom]
  • bar is invoked and the value of soom fetched, as if [list foo [bar] $soom] had been called
  • a command named foo is looked up in the current context
  • the current proc/lambda replaces itself in the call stack with a call to the just found command

That is: tailcall foo [bar] $soom is very similar to return [uplevel 1 [list foo [bar] $soom]]] with two exceptions:

  1. foo is looked up in the current context, not in the caller's
  2. the stack frame is really gone, not just virtually. This has positive effects on memory, and a possibly confusing effect on stack traces.