5 ms·
hey, thanks! i should have known that and didn't. i've corrected my comment above since you corrected me so quickly that i could still edit it! i feel like r
by kragen 2y ago
hey, thanks! i should have known that and didn't. i've corrected my comment above since you corrected me so quickly that i could still edit it!
i feel like readline and tab-completion is pretty important to a good command language, and plausibly you want to integrate support for tab-completion into the design of the language itself rather than having to write a separate completer for each command
i'm kind of puzzled why tclsh doesn't have any command-line editing. maybe ousterhout's team was only ever using tclsh in emacs shell-mode or something like your tk terminal? as an exercise, i wrote a basic command-line editor in c in bed on my cellphone the other night. it took me an hour and a half and 120 lines of code (with a very narrow line length to fit onto the cellphone screen), and it supports arrow keys, movement by words, word delete, about a dozen keystroke commands in all, which is most of the ones i use. (though i really need to fix the cbreak handling and handling of wide lines to work reliably.)
http://canonical.org/~kragen/sw/dev3/editline.c http://canonical.org/~kragen/sw/dev3/editline.c
tcl is about 200'000 lines of c; there's no reason for tclsh to be missing this
- wduquette 2y agoHistorically it’s because TCL uses the BSD license and GNU readline does not. But yeah, no reason not to implement an alternative. As for speed, it’s less that everything is a string (internally, data gets stored as both a string and whatever it last needed to be converted to) and more because TCL is so dynamic that compiling it is hard. There’s been some work on compiling to native though.
- kragen 2y agoi can see how upvar and uplevel could be a problem for compilation
- 082349872349872 2y agoupvar and uplevel are a significant barrier to optimisation, but not to plain compilation — the hardest part would be autovivification of fresh up-locals, and even that sounds like an extra indirection could reasonably handle it? EDIT: looks like tcl doesn't bytecode uplevel expressions, so I must be missing a catch?
- kragen 2y agoyeah, what i was thinking of specifically was that they would be a major barrier to optimization, which is the benefit one hopes for from compilation to be specific, it would be pretty hard to optimize a non-leaf procedure if any other procedure it called were able to violate any assumptions you'd made when optimizing it. elided redundant type checks, perhaps to specialize a proc? the proc it called changed the type of one of its variables. constant propagation? that proc changed the value of the variable you thought was constant. strength-reduction? likewise. you aren't going to get much dead code elimination without constant propagation. invariant hoisting? how are you going to figure out what's invariant if a proc you're calling inside the loop could change any of the variables used in it? register allocation? better have a way for upvar and uplevel to look up which register it was