Re: Tcl faster than Perl/Python...but only with tricks... [Idea?]
- From: George Petasis <petasis@xxxxxxxxxxxxxxxxx>
- Date: Sun, 31 Dec 2006 15:21:25 +0200
To my view, it will be nice if something is left out of all this,
so is it a good idea to try improve things?
How about starting a discussion on how to improve reading line by line a file, which is a quite frequent action (at least for me).
How about creating a new subcommand (in 8.5 chan command?), that will
perform an iteration over a channel content, similar to the way python does? For example, I can think of a command like:
chan foreach channelId {var1 ?var2 ...?} {split_chars-like-split} code
The idea is that Tcl_ReadObj is used to read pieces of the file in memory, and the split_chars are used to cut this into pieces, which are assigned into the variables. So,
chan foreach stdin line \n {
puts $line
}
will print a file line by line. The loop ends when eof/error occurs or when break is executed. And even provide a variation for lines, like:
chan foreachline channelId {var-list} code
And finally, mimic completely foreach, by allowing searches on multiple files:
chan foreach channelId-1 {var-list-1} {split-chars-1} \
?channelId-2 {var-list-2} {split-chars-2} ...? \
{code}
How about this idea?
Another idea that came to me while reading this post, was to implement a special list type objects, that will be bounded to files. For example:
chan split split-chars
this will return a "special" list object, whose internal representation will be bound to the channel. The file can be searched (preferably in a "lazy" way, i.e. only when it is needed) and keep internally offsets of the split characters. This way the object can return specific elements
by seeking the file. However, this is by far more complex than "chan foreach" and I doupt it will be more useful than "chan foreach".
Any opinions? :-)
Regards,
George
.
- References:
- Tcl faster than Perl/Python...but only with tricks...
- From: Stephan Kuhagen
- Tcl faster than Perl/Python...but only with tricks...
- Prev by Date: Re: Tcl faster than Perl/Python...but only with tricks...
- Next by Date: Re: Tcl faster than Perl/Python...but only with tricks...
- Previous by thread: Re: Tcl faster than Perl/Python...but only with tricks...
- Next by thread: Who uses peer text widgets?
- Index(es):