Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

goto in expect scripts

1,188 views
Skip to first unread message

Sooraj S

unread,
Oct 6, 2010, 9:03:54 AM10/6/10
to
Hi,

Is there any command in expect/tcl langauage similiar to goto in
perl..?

Can we write recursive functions in expect language?

neil mckay

unread,
Oct 6, 2010, 9:17:31 AM10/6/10
to
On Oct 6, 9:03 am, Sooraj S <soorajspadmanab...@gmail.com> wrote:
> Hi,
>
> Is there any command in expect/tcl langauage similiar to goto in
> perl..?

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

tom.rmadilo

unread,
Oct 6, 2010, 11:16:59 AM10/6/10
to

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.

Donal K. Fellows

unread,
Oct 8, 2010, 9:33:52 AM10/8/10
to
On 6 Oct, 14:03, Sooraj S <soorajspadmanab...@gmail.com> wrote:
> Is there any command in expect/tcl langauage similiar to goto in
> perl..?

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.

0 new messages