문제

I'm getting this weird issue. i'm using tcl 8.3

after i define this proc in a tcl shell

% proc incr { varName {amount 1}} {
    puts $varName
    upvar #0 $varName var
    puts $varName
    if {[info exists var]} {
       set var [expr $var + $amount]
    } else {
       set var $amount
    }
    return $var
}

i keep getting

%
history(nextid)
history(nextid)
history(oldest)
history(oldest)
%

Everytime i hit newline "Enter" after that any one has any idea why this is happening?

도움이 되었습니까?

해결책

Because the history managment is written in Tcl itself, and that uses incr.

Your incr is almost equal to Tcl 8.3's incr with some differences:

  • The name of the variable is always printed
  • If the variable does not exist, it will be created.

So if you remove the first difference (the puts) everything will work as expected, just that some library commands may call your incr instead the standard incr.

The second difference is now in the core, IIRC starting with Tcl 8.5 it is not nessencary that a variable already exists pior to calling incr.

In short: What you did is fine. But don't expect to be the only one who calls an standard command.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top