News for hackers. Stuff that matters.
Re:Learn X in Y minutes – Tcl by Johnny_Brahms on Tuesday August 25, 2015 @07:12AM (#10115626)
I haven't scrolled through more than a third and suddenly I have this strange feeling of wanting to write an IRC bot.

Jokes aside, TCL was for a long time my goto language for anything quick and dirty. As a result, I don't mind TCL at all. I still use Tk quite often. It might not look pretty, but it works and more crossplatform than other ui toolkits.

Re:Learn X in Y minutes – Tcl by kingmanaz on Saturday September 05, 2015 @02:20PM (#10175555)
Tk has come a long way since the 8.5 release. Tk now looks native. See http://www.tkdocs.com/tutorial/index.html for an excellent tutorial.
Re:Learn X in Y minutes – Tcl by amelius on Tuesday August 25, 2015 @07:44AM (#10115750)
I was hoping for a listbox with options for X and a slider controlling the value for Y :)
Re:Learn X in Y minutes – Tcl by sigzero on Tuesday August 25, 2015 @08:49AM (#10116044)
That's Tk. ;)
Re:Learn X in Y minutes – Tcl by meeper16 on Tuesday August 25, 2015 @06:01AM (#10115412)
Tcl is awesome.
Re:Learn X in Y minutes – Tcl by tonyjstark on Tuesday August 25, 2015 @06:03AM (#10115415)
can you elaborate? I always wonder if I should learn it, how it would make me think in new ways and how I would use it. Tcl looks strange and that makes it very interesting for me so how do you use it and why do you use Tcl for it?
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.
Re:Learn X in Y minutes – Tcl by meeper16 on Tuesday August 25, 2015 @06:19AM (#10115458)
I do a lot of text mining and it's one of the most efficient languages I've used over the years for doing things like this.
Re:Learn X in Y minutes – Tcl by a8da6b0c91d on Tuesday August 25, 2015 @08:03AM (#10115814)
That's an unusual assertion. Perl has much better facilities for working with unicode, and many other advanced facilities for parsing and so forth.
Re:Learn X in Y minutes – Tcl by bch on Tuesday August 25, 2015 @01:12PM (#10117989)
> Perl has much better facilities for working with unicode

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.

Re:Learn X in Y minutes – Tcl by eviltwinskippy on Tuesday August 25, 2015 @02:41PM (#10118642)
Not to mention that Tcl has Unicode in the core, has had Unicode in the core for at least 8 years, and the long and short is that EVERY string operation is Unicode aware.

You can have unicode procedure names, if that was your fancy.

Re:Learn X in Y minutes – Tcl by bch on Tuesday August 25, 2015 @02:57PM (#10118747)
...right, which is why I was wondering where Perl's support is superior. Tcl's support isn't perfect nor complete, but it's still pretty impressive.
Re:Learn X in Y minutes – Tcl by wrenky on Wednesday August 26, 2015 @02:35PM (#10125096)
I would like to see what advanced facilities perl has for text parsing that TCL doesn't!
Re:Learn X in Y minutes – Tcl by kbenson on Wednesday August 26, 2015 @11:12PM (#10127330)
Me too, but I suspect it might take someone of tchrist's level with experience in both languages to give a good answer. I would be interested in how TCL handles the issues tchirst has to deal with outlined in his famous SO post[1].

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

Re:Learn X in Y minutes – Tcl by reacweb on Tuesday August 25, 2015 @06:47AM (#10115532)
TCL/TK is incredibly powerful to put a GUI in front of a bunch of scripts. You can easily bind a regexp in a log file to events that update widgets. I wish I had learned it 20 years ago.
Re:Learn X in Y minutes – Tcl by ash on Tuesday August 25, 2015 @07:51AM (#10115778)
Could you give an example of that?
Re:Learn X in Y minutes – Tcl by mdaniel on Tuesday August 25, 2015 @04:34PM (#10119247)
If by "that" you mean an example of a GUI on top of scripts, the `git gui` and `gitk` that ship with git are in Tcl/Tk and shell out to the git commands that do the work

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.

Re:Learn X in Y minutes – Tcl by wrenky on Wednesday August 26, 2015 @02:25PM (#10125029)
We use TCL for almost everything that isn't C/C++, its insanely flexible. You can completely redefine the syntax if you want as there are NO keywords. Meta programming is easy, as all TCL commands follow the same format- Its only con is the lack of widespread use, so sometimes you'll have to write your own packages.

Dont worry to much though, the syntax grows on you :)

Re:Learn X in Y minutes – Tcl by stevekemp on Tuesday August 25, 2015 @08:42AM (#10116012)
This is a great introduction, by antirez of redis-fame.

http://antirez.com/articoli/tclmisunderstood.html

Re:Learn X in Y minutes – Tcl by msravi on Tuesday August 25, 2015 @09:06AM (#10116134)
Tcl is also the de-facto default language for almost all VLSI tools
Re:Learn X in Y minutes – Tcl by wainstead on Tuesday August 25, 2015 @05:02PM (#10119424)
This post occasionally makes the rounds and is an enlightening read:

http://antirez.com/articoli/tclmisunderstood.html

Re:Learn X in Y minutes – Tcl by sigzero on Tuesday August 25, 2015 @08:50AM (#10116053)
Yup, I whip up little one off utilities all the time with Tcl/Tk.
Re:Learn X in Y minutes – Tcl by josteink on Tuesday August 25, 2015 @06:40AM (#10115511)
Seems like an article ripe for pull-requests.

I've already sent one on a minor formatting issue, but about one third into that article, the formatting goes permanently haywire.

Weird how no one has noticed until now?

Re:Learn X in Y minutes – Tcl by Retr0spectrum on Tuesday August 25, 2015 @07:25AM (#10115678)
It looks like the syntax highlighter treated a * as the end of a comment, causing a " in the comment to be treated as the start of a string. That causes everything that isn't a string to be highlighted as one, and vice versa.
Re:Learn X in Y minutes – Tcl by robertskmiles on Tuesday August 25, 2015 @09:49AM (#10116419)
I've just started at a place that uses a lot of Tcl for embedded scripting and customisation, and I've never used it before so this was very handy.

That said, the document needs work - the syntax highlighting got very confused at some point, and a bunch of the lines are much longer than the width of the document, and don't wrap.

Tcl looks like a nice little language that makes it really easy to write really horrible code. Probably with some discipline you could keep it tidy and comprehensible though.

Re:Learn X in Y minutes – Tcl by bitwize on Tuesday August 25, 2015 @11:06AM (#10117005)
Tk is great but Tcl itself... it's interesting but the difficulty in creating real data structures (as opposed to just strings) makes me start reaching for Scheme again...
Re:Learn X in Y minutes – Tcl by srean on Tuesday August 25, 2015 @12:25PM (#10117606)
Tcl was never meant for that, the Ousterhout way would be to extend Tcl with the data structure written in C. Now Lua has knocked Tcl crown of "designed from scratch with embedding in mind" but at that time Tcl was indeed quite unique and one of the easiest to embed. This in a backhanded way inspired Guile: scheme intended to be embedded and/or extended.

Talking about Guile, lots of fun things happening there lately. wiki.tcl.tk is a lot of fun too.

Re:Learn X in Y minutes – Tcl by gioele on Tuesday August 25, 2015 @12:53PM (#10117835)
> at that time Tcl was indeed quite unique and one of the easiest to embed

Could you please explain why some languages are better at being "embedded and/or extended"? Why would Guile be simpler to embed than Ruby?

Re:Learn X in Y minutes – Tcl by bch on Tuesday August 25, 2015 @01:20PM (#10118063)
The Tcl shell itself (tclsh, which is many people's only interface with Tcl) is just a REPL that uses libtcl. The Tcl library is written in C, and built to be easy-to-use and powerful. Tcl also has an incredibly stable API/ABI which allows for a "stubs mechanism"[0] which is quite a nice, powerful facility that allows for seamless fixes to your Tcl-dependant work.

[0] http://www.tcl.tk/doc/howto/stubs.html

Re:Learn X in Y minutes – Tcl by srean on Tuesday August 25, 2015 @01:26PM (#10118120)
Great points. Something I feel that Tcl really got right and Python did not is handling concurrency. The Tcl way is to run the different interpreters in different threads and communicate between them by message passing but without the need for serialization - deserialization. They had this from the very beginning.
Re:Learn X in Y minutes – Tcl by bch on Tuesday August 25, 2015 @01:38PM (#10118214)
Yes. For multithreaded code, instead of deciding where/how to put interpreter locks (like Python's infamous GIL (global interpreter lock)) to manage low-level sanity wrt sharing data, Tcl punted and lets each interpreter run unfettered.

This is called apartment model [0] threading.

[0] https://msdn.microsoft.com/en-us/library/aa261361(v=vs.60).a... (this is a Microsoft VB article, with nothing to do about Tcl specifically, but does nicely explain the apartment threading model)

Edit: s/let's/lets/

Re:Learn X in Y minutes – Tcl by srean on Tuesday August 25, 2015 @01:22PM (#10118082)
Short answer: size, API and ease of resource management.

My comment was more about the state then than the state now. At that time few, if any languages were designed from scratch to be extended and embedded. Tcl and Guile, to my knowledge were among the first. Tcl interpreter is a library. IMO Guile has grown beyond that charter and is more of a stand-alone Scheme now, but one that can be easily embedded / extended, but so is Chicken I guess.

Re:Learn X in Y minutes – Tcl by nilkn on Tuesday August 25, 2015 @02:49PM (#10118702)
In addition to what others have mentioned, Tcl also has the speedtables extension, which is absurdly powerful for a lot of tasks.

https://github.com/flightaware/speedtables

Re:Learn X in Y minutes – Tcl by eviltwinskippy on Tuesday August 25, 2015 @02:01PM (#10118378)
You must not have used dicts, lists, associative arrays, or the sqlite intererface to Tcl.
Re:Learn X in Y minutes – Tcl by wrenky on Wednesday August 26, 2015 @02:34PM (#10125089)
Have you seen Tcl's dictionary construct? Its built in and extremely flexible in creating data structures, as you can define them from the ground up.
Re:Learn X in Y minutes – Tcl by tempodox on Tuesday August 25, 2015 @07:30AM (#10115695)
Before I say more: The “Tk” part of Tcl/Tk is the one redeeming quality about Tcl. Tk gives you awesome bang-for-the-buck when it comes to building a UI.

That said, Tcl is the worst parody of a programming language since the invention of BASIC and Brainfuck. All you need to know about it is two words: Stay away.

Re:Learn X in Y minutes – Tcl by gecko on Tuesday August 25, 2015 @10:29AM (#10116709)
I think you're being overdramatic, but since you didn't explain why you think Tcl is "the worst parody of a language since BASIC and Brainfuck", I can't really evaluate that. I can name lots of things about Tcl that are actually very pleasant, including the robust libraries, the homoiconic syntax, the ease of extending the language, the quickness that newbies can pick it up, and the performance (which is roughly on par with CPython, Perl and the like). What things have you hit that resulted in such an amazingly strong negative response?
Re:Learn X in Y minutes – Tcl by tempodox on Tuesday August 25, 2015 @10:44AM (#10116843)
The fact that there are no data types but only strings. The necessity to navigate dynamic scoping with `upvar` & siblings. The load of having to simulate locality of reference with fancy array indexes. It may be nice for simple string-crunching scripts but a complex application is living hell. You wouldn't use /bin/sh for that, either.
Re:Learn X in Y minutes – Tcl by tpoindex on Tuesday August 25, 2015 @11:56AM (#10117358)
Sounds like you haven't used Tcl since the early 1990's, you may want to check your facts. Tcl has had boolean, integer, floating point, list, dictionary, and other data types besides strings since 1997. The fact that Tcl will convert all of these values into strings when asked is immensely useful. Likewise, Tcl has had object oriented extensions since the early 1990's, and as of the last few years has OO built into the core, so you can easily build your data structures to suit.
Re:Learn X in Y minutes – Tcl by wrenky on Wednesday August 26, 2015 @02:29PM (#10125064)
This just isn't true, and hasn't been true since 92. Please go and take another look, its a very surprising language that more often than not beats or is comparable perl/python/js for speed.
Re:Learn X in Y minutes – Tcl by david-given on Tuesday August 25, 2015 @10:46AM (#10116859)
You can do some really interesting things with Tcl-ish technology. It's worth looking into TH1, the stripped-down embedded Tcl that's used by fossil as a macro language:

http://www.sqliteconcepts.org/THManual.pdf

The entire implementation's about 4k lines of code.

Re:Learn X in Y minutes – Tcl by RHSeeger on Tuesday August 25, 2015 @09:56AM (#10116459)
Personally, I find Tcl to be a fantastic language. It's extremely dynamic and powerful, making it very easy to accomplish a number of things that can be very difficult in other languages.
Re:Learn X in Y minutes – Tcl by sigzero on Tuesday August 25, 2015 @02:12PM (#10118467)
The Author (D. Richard Hipp) of SQLite uses Tcl extensively. I think that is a much better recommendation than "stay away". Use what you LIKE.
Re:Learn X in Y minutes – Tcl by SQLite on Tuesday August 25, 2015 @02:22PM (#10118533)
SQLite is a TCL extension that escaped into the wild....

I think many people have trouble with TCL because it looks a lot like C and so they expect it to behave roughly like C. But TCL is a fundamentally different language. It is better to think of TCL as LISP with C-like syntax. Once you grok this difference, TCL becomes a very elegant language.