Re: is possible to have a proc within a proc?
- From: "Donal K. Fellows" <donal.k.fellows@xxxxxxxxxxxxxxxx>
- Date: Thu, 29 May 2008 21:24:40 +0100
chedderslam wrote:
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.
If so, how would I do this?
No[*], but if you're using 8.5 you can use [apply] to get much the same
effect. As long as you don't want to refer to variables in the outer
context from the inner context without the use of [upvar], that is.
proc example {} {
set x {}
puts "this is the outer context, where x=$x"
apply {{} {
incr x 10
puts "this is inner context 1, where x=$x"
}}
append x foo
puts "this is the outer context, where x=$x"
apply {{} {
incr x 5
puts "this is inner context 2, where x=$x"
}}
append x bar
puts "this is the outer context, where x=$x"
apply {{} {
upvar 1 x x
lappend x boo
puts "this is inner context 3, where x=$x"
}}
append x hoo
puts "this is the outer context, where x=$x"
}
Donal.
[* We can have procedures creating other procedures though. ]
.
- References:
- is possible to have a proc within a proc?
- From: chedderslam
- is possible to have a proc within a proc?
- Prev by Date: Re: is possible to have a proc within a proc?
- Next by Date: dtp.kit
- Previous by thread: Re: is possible to have a proc within a proc?
- Next by thread: Re: is possible to have a proc within a proc?
- Index(es):
Relevant Pages
|