Re: Use "range," not "for"?
From: Andreas Leitgeb (avl_at_gamma.logic.tuwien.ac.at)
Date: 02/13/04
- Next message: Soares: "Expect script"
- Previous message: Arjen Markus: "Re: Problem with canvas items"
- In reply to: David McClamrock: "Use "range," not "for"?"
- Next in thread: Darren New: "Re: Use "range," not "for"?"
- Reply: Darren New: "Re: Use "range," not "for"?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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]}
?
- Next message: Soares: "Expect script"
- Previous message: Arjen Markus: "Re: Problem with canvas items"
- In reply to: David McClamrock: "Use "range," not "for"?"
- Next in thread: Darren New: "Re: Use "range," not "for"?"
- Reply: Darren New: "Re: Use "range," not "for"?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|