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.