3 ms·
I love TCL. The author points out my favorite aspect: "it has a radical minimalism". I use it for hobby projects because I work in Python all day professional
by fuball63 6y ago
I love TCL. The author points out my favorite aspect: "it has a radical minimalism". I use it for hobby projects because I work in Python all day professionally and like to mix it up a little in my free time. It feels very different but inhabits the same use case space.
That being said, here are some interesting things that tripped me up:
- using expr for arithmetic. The author mentions it, and it is cumbersome, but it also exemplifies what makes TCL special
- upvar for pass by reference. TCL does pass by reference by the command upvar, which says "take the variable named x in the scope above and assign it to the variable y in this scope". Confusing at first but a nice way to have pass by reference in a dynamic language
- docs are hard to read sometimes. The manual and tutorial for TCL are fantastic; the wiki is a little hard to read sometimes. The pages kinda seem like conversations, with authors weighing in on an article and tagging their names to their comments.
- lack of structured data. Saw another commenter posted this, and its something I wish TCL had better out of the box support for. The addition if dict was huge. The good news though: it's extremely easy to build a new command set to build a data structure out of dicts.
Despite all of this I'm a big fan of TCL. I try to tell as many people I can about it, because it really feels like a breath of fresh air compared to my day job Python. It allows you to be creative (and reckless!) with its power.
Edit: going to post the tutorial because it's so essential to getting started: https://tcl.tk/man/tcl8.5/tutorial/Tcl0.html https://tcl.tk/man/tcl8.5/tutorial/Tcl0.html
- _ph_ 6y agoIn newer TCL (8.5+) you can import mathop to get the typical operators as functions so that you do no longer need "expr".
- fuball63 6y agoDoes that happen automatically in some cases? I think I'm on 8.6 and I'm pretty sure I forgot the expr and it worked OK. Could have been a string operation or something, I don't have the code to check on hand.
- suyjuris 6y agoThe string command accepts a special syntax for indices, which includes addition (but not the full power of expr) [1]. Maybe you are referring to this? Also, list commands accept the same syntax for list indices. Example: % string index abc 1 b % string index abc 1+1 c % string index abc 1+1+1 bad index "1+1+1": must be integer?[+-]integer? or end?[+-]integer? % string index abc end-1 b [1] http://www.tcl.tk/man/tcl8.6/TclCmd/string.htm#M54 http://www.tcl.tk/man/tcl8.6/TclCmd/string.htm#M54
- dvdkhlng 6y agoWell, you don't need 'expr' in contexts were an expression is expected, e.g. 'if' 'while', 'for' (2nd arg).
- fuball63 6y agoI think that this is what I was experiencing.
- zeckalpha 6y agoPython includes a Tcl, you should be able to use Tcl inside your Python projects just fine technically. Socially, might not work out.
- davidw 6y agoNot a big deal, but it's generally "Tcl" these days, not TCL.
- yesenadam 6y agoIt's easy to alias expr to =, which enhances readability : % interp alias {} = {} expr = % set x [= 2 + 3] 5 Also aliasing lindex to @ is nice % interp alias {} @ {} lindex % set a {1 2 3} 1 2 3 % @ $a 1 2