Incr Tcl: Something like a scoped object
- From: antred <NutJob@xxxxxxx>
- Date: Thu, 29 Nov 2007 23:46:44 -0800 (PST)
Hello,
Does Incr Tcl offer something like scoped variables in C++ or context
managers in Python? That is, an object that, as soon as it goes out of
scope, automatically has a certain finalization method invoked on it?
I'd find that immensely useful if it did exist.
An example:
::itcl::class SomeClass {
public destructor {} {
puts "Destructor called."
}
}
proc someProc {} {
set myScopedObject [ SomeClass \#auto ]
# Do tons of interesting stuff.
# ...
# ...
# myScopedObject goes out of scope ... destructor is invoked
automatically.
}
That's how I'd like it to be. Unfortunately the way it is I have to
call object delete $myScopedObject to get the destructor invoked.
Don't get me wrong, I don't want to override the standard behavior for
all class objects, but in some cases it would be really nice. Without
this ability, use of RAII pattern is pratically impossible in Tcl,
which I find a serious limitation.
Regards,
ant
.
- Follow-Ups:
- Re: Incr Tcl: Something like a scoped object
- From: Stéphane A.
- Re: Incr Tcl: Something like a scoped object
- From: suchenwi
- Re: Incr Tcl: Something like a scoped object
- Prev by Date: Re: Tcl under conditions of high memory usage.
- Next by Date: Re: Incr Tcl: Something like a scoped object
- Previous by thread: error with tktable and mac OS 10.3
- Next by thread: Re: Incr Tcl: Something like a scoped object
- Index(es):