Re: TclX loop slow in the default case



On Aug 28, 3:03 am, "Donal K. Fellows" <donal.k.fell...@xxxxxxxxx>
wrote:
Alexandre Ferrieux wrote:
Why a wrong analysis ? How would you define [loop] in pure Tcl so that
it has the same performance as a [for] ?

In 8.5 and before, you can't because the body script will not be
compiled to have efficient access to local variables. (This might
change in 8.6 AIUI.) But apart from that you can get close:

proc loop {var from to body} {
upvar 1 $var v
for {set v $from} {$v <= $to} {incr v} {
uplevel 1 $body
}
}

What about [uplevel {for ...}] instead of [for ... uplevel] ?
(Miguel, what versions received your patch bringing compilation of
[uplevel] ?)

proc loop {var from to body} {
uplevel 1 [list for [list set $var $from] "\$$var<$to" [list incr
$var] $body]
}

-Alex
.



Relevant Pages

  • Re: Redeclaration problem with CC
    ... When you compiled main.c the int var; in "toto.h" is processed creating a ... giving you 2 definition for var which your linker reasonably complains ... The _toto_h include guard only works within a single compilation unit. ... To fix your multiple definition problem make "toto.h" declare rather ...
    (comp.lang.c)
  • Re: TclX loop slow in the default case
    ... compiled to have efficient access to local variables. ... proc loop { ... moment because we don't currently reconnect the compilation of the ... the TclX loop command is actually less ...
    (comp.lang.tcl)
  • Re: Ron Garret considered harmful [Re: DEFSTRUCT and lexical environment]
    ... I am restricting myself to the CL spec. ... See 3.2.2.2 Minimal compilation. ... See, because macros are programmer-defined, and can contain side ... and not change even if subsequently *var* changes before the compiled ...
    (comp.lang.lisp)