GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
tailcall(n) Tcl Built-In Commands tailcall(n)


tailcall - Replace the current procedure with another command

tailcall command ?arg ...?

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.

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]
    }
}

apply(n), proc(n), uplevel(n)

call, recursion, tail recursion
8.6 Tcl

Search for    or go to Top of page |  Section n |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.