Version 3 of recursion

Updated 2005-04-08 19:48:50 by suchenwi

Richard Suchenwirth 2005-04-08 - What happens when a proc calls itself. Popular in functional programming. In Tcl, we're a bit handicapped by the [interp recursionlimit] which is at ~380 on Windows, even if set higher.

Here's an example for a recursive integer range generator, so that [iota1 5] == {1 2 3 4 5} :

 proc iota1 n {expr {$n == 1? 1: [concat [iota1 [- $n 1]] $n]}}

rdt For completeness, shouldn't your definition of - (from http://wiki.tcl.tk/11389 ) be here also? - RS: Oops, of course - just another one-liner :)

 proc - {a {b ""}} {expr {$b eq ""? -$a: $a-$b}}

Category Concept | Arts and crafts of Tcl-Tk programming