Re: New question on strings



On Feb 28, 9:58 am, "tom.rmadilo" <tom.rmad...@xxxxxxxxx> wrote:
On Feb 28, 7:44 am, Neil Madden <n...@xxxxxxxxxxxxx> wrote:

tom.rmadilo wrote:
OMG, is this another one of those regressions? I guess so. [Incr] now
auto initializes to zero if the variable doesn't exist.

See TIP 215

BTW, initialization is a complex subject. With the changes that auto-
initialize lists and strings, [lappend], [append], maybe others, you
get an small benefit during an initial setup, but if you use a
variable in a loop, you instantly run into the problem of re-
initialization. Considering the fact that [incr] essentially implies a
loop of some type, that is some code is being executed multiple times,
the tiny benefit of auto-initialization seems more like a C-like
syntax optimization that just makes code harder to read, maintain and
debug.

Another ambiguity is if a variable is supposed to exist prior to an
[incr] statement:

namespace eval ::num {
variable i
}
proc ::num::get { } {
return [incr i]
}

Code looks perfect, but they probably meant:

proc ::num::get {} {
variable i
return [incr i]
}

These are not typos, these are examples where things work, and the
original intent is not obvious. If someone were to look at the code,
with the bug, and tried to write up a regression test, is their job
made easier?
.



Relevant Pages

  • Re: New question on strings
    ... incr versus five lines to do a test and an incr or a set. ... This only works for initialization the first time through. ... If you loop ... delete the array (if it wasn't an array it would become impossible to ...
    (comp.lang.tcl)
  • Re: Trying to use STRING
    ... that you do think 'what if', but as Richard says, it CANNOT happen. ... nothing to stop the group level field (ws-balanceX) being initialized ... "A loop-with-exit loop is a loop in which the exit condition ... one for initialization and the other for the inspect itself. ...
    (comp.lang.cobol)
  • Re: LOOP blows!
    ... and initialization of all variables takes place in the prologue. ... the initial `binding' of loop vars for all other FOR-AS ... So FOR-AS-EQUALS differs from other for clauses in another way: ... | tests and the loop body. ...
    (comp.lang.lisp)
  • Re: LOOP blows!
    ... At beginning of each iteration. ... All variables in the FOR clauses ... ] All variables are initialized in the loop prologue. ... Initialization is not assignment! ...
    (comp.lang.lisp)
  • Re: Order of execution question
    ... pass through the loop, not on the entry to the loop. ... The local declaration and initialization of temp. ... I'm not going to tell you to stop making mistakes; ...
    (comp.lang.c)