News for hackers. Stuff that matters.
Re:Learn X in Y minutes – Tcl by sebcat on Tuesday August 25, 2015 @11:45AM (#10117263)

  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.
Re:Learn X in Y minutes – Tcl by sigzero on Tuesday August 25, 2015 @12:12PM (#10117470)
I like the "with". Python has that construct. It's not annoying and easy to remember.
Re:Learn X in Y minutes – Tcl by a8da6b0c91d on Tuesday August 25, 2015 @12:03PM (#10117412)
Still leaks on an exception. That's also an annoying construct to be forced to use.
Re:Learn X in Y minutes – Tcl by nilkn on Tuesday August 25, 2015 @12:43PM (#10117762)
You could easily wrap the middle uplevel in a catch block to handle exceptions, and this sort of "with" construct is pretty common in a lot of very popular languages today.

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.

Re:Learn X in Y minutes – Tcl by srean on Tuesday August 25, 2015 @01:34PM (#10118179)
I think this precisely one of Tcl's strengths. Few other languages apart from Lisp and Tcl lets you write your own control flow syntax from within the language (and at runtime).