Is there any command in expect/tcl langauage similiar to goto in
perl..?
Can we write recursive functions in expect language?
In a word, no. Tcl has no goto statement, and the way Tcl was
originally implemented,
it would have been extremely difficult to implement a goto.
>
> Can we write recursive functions in expect language?
Yes, Tcl (and therefore expect) DOES have recursive functions.
Neil McKay
Using Tcl:
proc ::someNamespace::myProc { args } {
variable someVar
while {1} {
switch -exact -- $goto {
state1 {
...
set goto state2
}
state2 {
...
set goto state1
}
default {
cleanupState
break
}
}
}
}
You can easily convert well written C code which uses goto with the
above outline, if you need specific examples, I'll provide links.
No. There is [break] and [continue] and [error] and [switch], and you
can make your own control structures (including state machine
evaluators, such as Tom's example shows) but there is no goto.
However, in 8.6 (in beta) there are some extra goodies. In particular,
Perl's goto-a-subroutine *can* be done with the new [tailcall] command
and return to a particular spot that you were at before can be done if
you're using [coroutine] and [yield] (even into calls to other
procedures if necessary). Still no general [goto] though (it's really
a bit too primitive to work with Tcl's model of the world).
> Can we write recursive functions in expect language?
Yes!
There's a limit on how deep you can recurse by default, and [interp
recursionlimit] can be used to manipulate that limit, but you can go
as deep as you have stack space for. In 8.6, it instead depends on
your heap space, which lets you go *extremely* deep (I've had testing
code go over 1 million recursive calls in without difficulty...)
Donal.