Artifact 6b9eb17cc72e706899058d076b23c6a46f0b869cfd639d265d8969fb59b9dc5e:
- File doc/markdown/Tcl/tailcall.md — part of check-in [b84ce0eee1] at 2026-10-04 22:10:02 on branch tip-700 — file location re-organisation (part 1) (user: Torsten, size: 1677) [annotate] [blame] [check-ins using]
- File doc/markdown/tailcall.md — part of check-in [5e80e55e41] at 2026-09-26 22:40:07 on branch tip-700 — - added a "title" metadata element to the generated yaml block to satisfy Pandoc when converting to HTML - added markdown2html.tcl as prototype/placeholder of conversion script markdown -> HTML - added some CSS to play with a good visual representation of the generated HTML, starting with the n section pages - fixed man2markdown.tcl not giving the two .TP/.IP parsing places the same treatment (user: Torsten, size: 1677) [annotate] [blame] [check-ins using]
CommandName: tailcall title: tailcall ManualSection: n Version: 8.6 TclPart: Tcl TclDescription: Tcl Built-In Commands Links:
- apply(n)
- proc(n)
- uplevel(n) Keywords:
- call
- recursion
- tail recursion Copyright:
- Copyright (c) 1993 The Regents of the University of California.
- Copyright (c) 1994-1996 Sun Microsystems, Inc. ---
Name
tailcall - Replace the current procedure with another command
Synopsis
::: {.synopsis} ::: [tailcall]{.cmd} [command]{.arg} [arg]{.optdot} :::
Description
The tailcall command replaces the currently executing procedure, lambda application, or method with another command. The command, which will have arg ... passed as arguments if they are supplied, will be looked up in the current namespace context, not in the caller's. Apart from that difference in resolution, it is equivalent to:
return [uplevel 1 [list command ?arg ...?]]
This command may not be invoked from within an uplevel into a procedure or inside a catch inside a procedure or lambda.
Example
Compute the factorial of a number.
proc factorial {n {accum 1}} {
if {$n < 2} {
return $accum
}
tailcall factorial [expr {$n - 1}] [expr {$accum * $n}]
}
Print the elements of a list with alternating lines having different indentations.
proc printList {theList} {
if {[llength $theList]} {
puts "> [lindex $theList 0]"
tailcall printList2 [lrange $theList 1 end]
}
}
proc printList2 {theList} {
if {[llength $theList]} {
puts "< [lindex $theList 0]"
tailcall printList [lrange $theList 1 end]
}
}