"Fossies" - the Fresh Open Source Software Archive

Member "SAOImageDS9/tcl8.6/doc/tailcall.n" (13 Nov 2019, 1935 Bytes) of package /linux/misc/ds9.8.1.tar.gz:


Caution: As a special service "Fossies" has tried to format the requested manual source page into HTML format but links to other man pages may be missing or even erroneous. Alternatively you can here view or download the uninterpreted manual source code. A member file download can also be achieved by clicking within a package contents listing on the according byte size field.

tailcall

NAME
SYNOPSIS
DESCRIPTION
EXAMPLE
SEE ALSO
KEYWORDS

NAME

tailcall − Replace the current procedure with another command

SYNOPSIS

tailcall command ?arg ...?

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

SEE ALSO

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

KEYWORDS

call, recursion, tail recursion