I solved it finally. when Length() function defined as protected this error shown. so I define it as public and this problem solved :)
but for solving any error on tcl you can use following command :
valgrid --track-check=yes ns filename.tcl
after running this command you can see position and cause of errors. I used it to find cause of my problem and saw "memory stack". this means the program can't access to memory for protected function!