Prev: How to do channel redirection?
Next: grab and interp
From: Kevin Kenny on 22 Dec 2009 09:15 Rodericus wrote: > It is funny to see how many features must be added to a programming > language only to eliminate the use of goto because it may be misused > for writing unreadable programs. Why you allow Tcl write programs that > modify themeselvs? Cannot be this misused for writing unreadable > programs? Tcl's lack of 'goto' does not come from any sense of ideology; it is actually a subtle consequence of 'everything is a string.' The way that Tcl approaches a construct like while {condition} {script} is that the condition and the script ARE BOTH STRINGS. At least conceptually, until the 'while' command begins executing, there is no requirement that the 'condition' be an expression or that the 'script' be a script. In fact, code that redefines 'while' (yes, that's legal, if foolhardy) is free to interpret them as it pleases. So all the interpretation is local. If you have a typical set of stuff like: for {set i 0} {$i < $max} {incr i} { if {[something]} { do something } else { do something else } } the interpreter sees a command called 'for' taking four arguments. Only once 'for' begins executing does it begin to interpret {set i 0}, {incr i} and {if {[something]} ...} as scripts. Similarly, the 'if' is also simply a command, with four arguments. Only once the 'for' has asked to interpret the inner script does Tcl parse it into a command, and then execute it, and only then does 'if' try to interpret the inner scripts. (Yes, the bytecode compiler actually interprets stuff more aggressively. But it's required to behave as if it worked as if I just described it. And in fact there are circumstances, such as redefining [if], in which the executing bytecode needs to be discarded and regenerated.) And it's perfectly legal to write code like: proc hello {} { puts "hello, world!" return The stuff here is utter rubbish, with the only constraint on it being that curly braces have to balance. The interpreter doesn't actually interpret it. } So in a real sense, the problem isn't the 'goto', it's the 'come from'. We can't execute a 'goto' until we've parsed an entire script, so that we know where all the labels are. And we (at least conceptually) do not parse entire scripts. -- 73 de ke9tv/2, Kevin
From: Don Porter on 22 Dec 2009 11:16 Kevin Kenny wrote: > And it's perfectly legal to write code like: > > proc hello {} { > puts "hello, world!" > return > The stuff here is utter rubbish, with the > only constraint on it being that curly > braces have to balance. The interpreter > doesn't actually interpret it. > } Just for the sticklers for detail, that statement is true in Tcl 7.* and earlier and in Tcl 8.5 and later, but not true in the releases 8.0 - 8.4. In those middle releases, the initial implementation of the bytecode compiler raised an error when compiling any "script" that lacks valid Tcl syntax, or when apparent compiled commands violated their own syntax rules (such as [set too many args]). To tie this into the original theme, this is an example where recent Tcl releases have actually been returning to the original vision, not departing from it. Numbers that adhere to EIAS are another example. DGP
From: Rodericus on 22 Dec 2009 12:51 On 22 Dez., 15:15, Kevin Kenny <kenn...(a)acm.org> wrote: > Tcl's lack of 'goto' does not come from any sense of ideology; it > is actually a subtle consequence of 'everything is a string.' [...] It is a good feeling to know that there is a good reason. Rodrigo.
|
Pages: 1 Prev: How to do channel redirection? Next: grab and interp |