Re: is possible to have a proc within a proc?



ZB wrote:
Dnia 29.05.2008 chedderslam <chedderslam@xxxxxxxxx> napisał/a:

I am working on a proc which calls itself recursively. Is it possible
for a proc to have a proc within itself? I am trying to group the
code together.
Pascal will do this. Tcl will not.

Mike
Thank you.

Actually you can nest a function using "apply" - a very simplistic example:

proc makeSomething { x y } {
puts "$x | $y"
apply {{x y} {expr $x*$y}} $x $y
}

tclsh8.5 [~]makeSomething 3 4
3 | 4
12


Even better (or rather, closer to what I guess the original poster wants):

% proc makeSomething { x y } {
puts "$x | $y"
set p [list ::apply {{x y} {expr $x*$y}}]
puts [{*}$p $x $y]
puts [{*}$p $x [incr y]]
}
% makeSomething 3 4
3 | 4
12
15
.



Relevant Pages