Re: Use "range," not "for"?

From: Andreas Leitgeb (avl_at_gamma.logic.tuwien.ac.at)
Date: 02/13/04


Date: 13 Feb 2004 09:48:17 GMT

David McClamrock <mcclamrock@locl.net> wrote:
> I've found that a simple "foreach" loop fairly often won't do the jobs I
> want done, and I need to use "for"--ugh! Well, I recently read at least
> part of a book about Python. It didn't look like an improvement over Tcl
> for the most part, but it has at least a few good features, one of which is
> the "range" expression.

It's funny, how experience can be similar and yet completely
different:

I have read a book about Python, too, but I kind of dropped it,
 just because Python had no such thing as the classic
 "init/condition/incr"-controlled for-loop.

I posted to python-group, asking what pythoneers do in such cases,
 where such a for-loop is necessary, and all they came up was either
 the for_with_range-thing(1) or while-loops(2).
Both were not satisfactory:
(1) wouldn't give me "write-access" to the loop-variable, and
(2) misses the "incr"-part, that will be jumped to at a "continue".
  Answering to this, some came up with exception-handling tricks to
  work around that, but thats unpracticable.

Creating a list of numbers in memory just to iterate this list
seems somewhat strange to me.

The only really cool thing about Python is the concept of "generators".
I think some time ago, I've heard some thoughts about lazy evaluation-
concepts in Tcl, but have no idea what became of it.

Seeing the indentation chaos that differing tab-size-settings of
 different developers cause, I sometimes wish tcl,C,C++ and Java
 would care for indentation like python, but, well, I know this
 is never going to happen, and it's likely better this way.

> Or, if you have a list called "lum," instead of writing this:
> for {set i 0} {$i < [llength $lum]} {incr i} {puts [lindex $lum $i]}
Isn't this exactly what tcl's "foreach" is for?
% foreach i $lum {puts $i}
Isn't this nicer than:
> range i 0 no [llength $lum] {puts [lindex $lum $i]}
?



Relevant Pages

  • Re: TCL with Perl or Python?
    ... Now that you mentioned web guis, tcl is far behind on this :-( ... I want to add a small web gui to an existing app, and still I haven't found a solution... ... using Python or Perl. ...
    (comp.lang.tcl)
  • Re: Tcl faster than Perl/Python...but only with tricks...
    ... I have tried some small variations by mimicking your first python code. ... the tcl code that does similar to the python code is: ... python python.py: 582543 microseconds per iteration ...
    (comp.lang.tcl)
  • Re: Choosing Perl/Python for my particular niche
    ... >I was under the impression that Tcl ... >it's good to know that Tcl is an option to Perl and Python, ... >algorithms for programming coarse grain reconfigurable ...
    (comp.lang.perl.misc)
  • Re: Choosing Perl/Python for my particular niche
    ... >I was under the impression that Tcl ... >it's good to know that Tcl is an option to Perl and Python, ... >algorithms for programming coarse grain reconfigurable ...
    (comp.lang.python)
  • Re: Python for TCLer
    ... >I am almost brainwashed to forsake TCL for Python. ... >to ask a few preliminary questions before I jump in. ... One of my vendors supplies TCL package only. ... We have one control structure in our API that has done ...
    (comp.lang.python)