1

I have written known proc to handle some scenarios. I have written as

proc unknown args {
    if { ![regexp {65ABC::\w+\s.*} $args] } {
        uplevel 1 [list _unknown $args]
    }
}

When i am typing some wrong command say acbsv in TCL, it is throwing an error as

too many nested evaluations (infinite loop?)

Solution: If i am adding the command

rename unknown _unknown

It is working but don't why I am getting the error and why it is getting resolved when I am adding rename command

1
  • Did you create the proc named unknown and have you also used rename unknown unknown_ earlier in the script? My guess is that the proc unknown that you used will have the answer there. Commented Mar 31, 2014 at 6:43

1 Answer 1

2

If you define unknown to call _unknown but there is no _unknown command, what happens? Easy! Tcl calls unknown to try to fix things. With a simplistic unknown definition, this can result in a recursive loop of trying to handle an absent _unknown by calling _unknown but that is absent so we call _unknown but that is absent so we call _unknown and so on…

acbsv --> "no such command; call unknown"
  unknown acbsv --> "I can do this..."
    _unknown acbsv --> "no such command; call unknown"
    unknown _unknown --> "I can do this..."
      _unknown _unknown --> "no such command; call unknown"
      unknown _unknown --> "I can do this..."
        _unknown _unknown --> "no such command; call unknown"
        unknown _unknown --> "I can do this..."
          _unknown _unknown --> "no such command; call unknown"
          unknown _unknown --> "I can do this..."
            ...

Tcl imposes a limit on the maximum stack depth to prevent this sort of thing causing real problems. You can raise the stack depth limit (e.g., with interp recursionlimit {} 1500) if you need it, but you are advised to only do that if you do need it. Most code doesn't, as Tcl programmers tend to write imperative iterative code, not functional code. (The hard limit is fairly low in Tcl 8.4 and 8.5, as recursive Tcl calls result in recursive C calls and some of the things in there have substantial activation records. Tcl 8.6 has no such limits due to using a “stackless” implementation; you can go as deep as your heap memory allows if you want.)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.