News for hackers. Stuff that matters.
Re:Learn X in Y minutes – Tcl by _pmf_ on Tuesday August 25, 2015 @06:42AM (#10115516)
It offers the syntactic freedom of Lisp/Scheme without the parentheses.
Re:Learn X in Y minutes – Tcl by _ph_ on Tuesday August 25, 2015 @07:27AM (#10115688)
The top level of parenthesis-es is left out, the other levels replaced by brackets :). But joking aside, I greatly enjoy both Lisp and Tcl as languages.
Re:Learn X in Y minutes – Tcl by a8da6b0c91d on Tuesday August 25, 2015 @09:06AM (#10116133)
A huge, seriously annoying problem with TCL is lack of deterministic cleanup for resources. If you don't manually close a filehandle, for example, it will leak. Doing this sort of bookkeeping in 2015 is infuriating.
Re:Learn X in Y minutes – Tcl by sigzero on Tuesday August 25, 2015 @12:08PM (#10117440)
This illustrates how you can use Tcl to ensure that files get closed even when errors happen by combining catch, close and return (from the Tcl manual):

    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
    }
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).
Re:Learn X in Y minutes – Tcl by AnimalMuppet on Tuesday August 25, 2015 @04:16PM (#10119167)
Garbage collecting languages will free memory, but that's all they're good for. C++ destructors will let you close a filehandle, but I know of no other language that will deterministically clean up non-memory resources.

So: What language(s) did you have in mind that do this right?

Re:Learn X in Y minutes – Tcl by _ph_ on Tuesday August 25, 2015 @05:45PM (#10119655)
Lisp for example has unwind-protect, which is guaranteed to run the unwind code when you leave its scope in which way whatever (be it an exception or a return). So this is a reliable way of running clean-up code at the end of a code block.
Re:Learn X in Y minutes – Tcl by a8da6b0c91d on Tuesday August 25, 2015 @04:49PM (#10119352)
Many scripting languages in practice do reference counting GC that will reliably and deterministically clean up resources other than memory.
Re:Learn X in Y minutes – Tcl by sigzero on Tuesday August 25, 2015 @05:58PM (#10119725)
"Many" includes Tcl there. I have no idea why you think differently. Tcl has had it since the 8.X series started (at least).
Re:Learn X in Y minutes – Tcl by a8da6b0c91d on Tuesday August 25, 2015 @06:32PM (#10119876)
Not for tcloo objects, channels and file handles. I don't think you get it. In sane languages like C++ you can expect a destructor to call itself no matter where a function exited.
Re:Learn X in Y minutes – Tcl by sigzero on Tuesday August 25, 2015 @07:21PM (#10120100)
C++ is not a scripting language. Give me a scripting language that does that so I can research and compare.
Re:Learn X in Y minutes – Tcl by a8da6b0c91d on Tuesday August 25, 2015 @07:51PM (#10120218)
perl:

    sub do_stuff {
        my $thing = Thing->new; # no need to manually destroy thing. Its DESTROY method will be called at the closing brace.
    }
Re:Learn X in Y minutes – Tcl by sigzero on Tuesday August 25, 2015 @09:21PM (#10120469)
Cool...now I get to play. Perl does it because it goes out of scope once the sub is run. I am pretty sure you can tell TclOO to do the same thing (play time) if it already doesn't do that.

In the end, they all make trade offs depending on the "whim" of the language designer.

Re:Learn X in Y minutes – Tcl by a8da6b0c91d on Tuesday August 25, 2015 @09:35PM (#10120504)
Jesus Christ, you don't even know tcl. Why are you blathering on here? No, tcloo objects are not garbage collected. That's the whole point here.
Re:Learn X in Y minutes – Tcl by sigzero on Tuesday August 25, 2015 @10:26PM (#10120676)
Yeah just blathering. Carry on.
Re:Learn X in Y minutes – Tcl by AnimalMuppet on Wednesday August 26, 2015 @12:43PM (#10124210)
So, about four posts before this one, you said:

> 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?

Re:Learn X in Y minutes – Tcl by eviltwinskippy on Tuesday August 25, 2015 @02:39PM (#10118625)
Programming must by hard for you. Have a cookie.