Re: New question on strings



tom.rmadilo wrote:
I really don't get the point of making the easiest possible thing
(initializing a variable) even easier.

I think it boils down to this: somebody saw a need that others have expressed as well over the years. This person spent their own personal time to submit the tip, work to get it accepted, wrote the code, updated the docs, and updated the tests.

Then, we had well more than a year to beta test this particular feature. In that time I don't think anybody complained, so it ended up becoming a feature of the language.

As to why someone would spend all this time to "[make] the easiest possible thing ... easier"... my guess is that it makes it makes the following pattern quite easy:

foreach line <some set of data ...> {
if {<some criteria is met>} {
incr count(<some index>)
}
}

Prior to this change it had to be written like:

foreach line <some set of data> {
if {<some criteria is met>} {
if {[info exists count(<some index>)]} {
incr count(<some index>)
} else {
set count(<some index>) 0
}
}
}

Many feel the first is preferable to the second -- one line to do an incr versus five lines to do a test and an incr or a set.

<shrug>

I think now that the feature is part of the language it's here to stay, so there's not much point in debating it.


--
Bryan Oakley
http://www.tclscripting.com
.



Relevant Pages

  • Re: files created, filled, incremented
    ... puts $Idfile ... incr _noligne ... You open the file outside of the foreach loop, ... puts $channel ... ...
    (comp.lang.tcl)
  • Re: New question on strings
    ... Bryan Oakley wrote: ... if {<some criteria is met>} { ... Mistakenly doing [incr $counter] is way up on my list along with mistakenly writing code like ... Darren New / San Diego, CA, USA (PST) ...
    (comp.lang.tcl)
  • Re: The switch "procedure"?
    ... while {[incr i -1]} ... Giving the thing a new name (a proc name, ... interp alias for foreach _ _) and use that name ...
    (comp.lang.tcl)
  • Re: puts "abcd $a$b" in a loop, gvs err
    ... % puts "abcd $a$b" ... % foreach l $rt0protos { ...
    (comp.lang.tcl)
  • Re: alternative to nested loops?
    ... foreach a $list_A { ... compare. ... $a_list]}]} {incr i} { ... proc fuzzzy { ...
    (comp.lang.tcl)