proc withOpenFile {filename channelVar script} {
upvar 1 $channelVar chan
set chan [open $filename]
catch {
uplevel 1 $script
} result options
close $chan
return -options $options $result
} proc with {file as name block} {
uplevel 1 [list set $name $file]
uplevel 1 [list eval $block]
uplevel 1 [list close $file]
}
with [open foo.txt w] as file {
puts $file "Hello, World!"
}
I'm sure it's possible to do it in a cleaner way without [set], but my Tcl is a bit rusty.While it would be nice if this were baked into the language, it's pretty astonishing how extensible Tcl is without even having to touch the realm of C extensions.
So: What language(s) did you have in mind that do this right?
sub do_stuff {
my $thing = Thing->new; # no need to manually destroy thing. Its DESTROY method will be called at the closing brace.
}In the end, they all make trade offs depending on the "whim" of the language designer.
> Many scripting languages in practice do reference counting GC that will reliably and deterministically clean up resources other than memory.
When challenged, you offered one. So, is this a Perl-only thing, or can you give other examples?
Which facilities are those ?
> many other advanced facilities for parsing
Be curious to hear what those are, but note that Tcl is hilariously simple to extend and build up custom constructs to suit ones needs.
You can have unicode procedure names, if that was your fancy.
Note: If you read that post and think, "Wow, Perl requires a lot of setup for unicode and TCP doesn't require nearly as much" without understanding the specifics of why each step is there, and how TCL handles the same issue, you are likely underthinking the issue.
1: http://stackoverflow.com/questions/6162484/why-does-modern-p...
As others have mentioned, they are very, very not "native UI" friendly - OSX is an especially bad instance - but they do run on all of Git's platforms without a 20MB runtime to go along with them. If Tk's widgets were just a little less harsh, those two would absolutely be my go-to graphical git clients.
Dont worry to much though, the syntax grows on you :)