Path: utzoo!attcan!uunet!husc6!cca!g-rh
From: g-rh@cca.CCA.COM (Richard Harter)
Newsgroups: comp.lang.misc
Subject: Re: State Machines, The Ultimate Goto
Message-ID: <27860@cca.CCA.COM>
Date: 12 May 88 16:23:04 GMT
References: <1988Apr8.183815.3187@utzoo.uucp> <449@goofy.megatest.UUCP> <2200@louie.udel.EDU> <587@vsi.UUCP> <27310@cca.CCA.COM> <760@dlhpedg.co.uk> <27568@cca.CCA.COM> <4627@ihlpf.ATT.COM> <27744@cca.CCA.COM> <4726@ihlpf.ATT.COM>
Reply-To: g-rh@CCA.CCA.COM.UUCP (Richard Harter)
Organization: Computer Corp. of America, Cambridge, MA
Lines: 54

In article <4726@ihlpf.ATT.COM> nevin1@ihlpf.UUCP (00704a-Liber,N.J.) writes:
>In article <27744@cca.CCA.COM> g-rh@CCA.CCA.COM.UUCP (Richard Harter) writes:

	... Defintions deleted ...

>Given this I pose a question:  which branch of logic, procedure or goto, do
>things like for loops and while loops fall under?  They seem to be a little
>of both.

	Procedure logic -- the loop considered as a block, has a return
point (next statement to be executed after the block) associated with...

... re simulating gotos with procedures, he observes that procedure
calls are more expensive.

	Quite true.  However this cost is a fixed cost, i.e. the equivalent
program will be slower, at most, by a fixed constant of proportionality.
The rate of slowdown is independent of program size or execution time.


>|Conversely there are programs using procedures which cannot be replaced by
>|a program only using gotos without paying a penalty either in space or time.

>Only because in this case you have to explicitly store some data.  If you
>make the assumption that it takes 0 seconds to store a value (this is
>the assumption that you made when you stated that there is no penalty for
>simulating goto logic with procedural logic), goto logic will NOT pay a
>penalty in either space or time.  I think that goto logic with storage can
>be shown to be equivalent to procedure logic.

Actually you are mixing two different constructs, 'goto to a prespecified
address' and 'goto a computed address'.  The key point is whether you
can change the place that the goto transfers to during execution.  The
order of strengths is

	fixed goto
	procedure call/return
	computed goto

The reason that you can't emulate procedures with fixed gotos with constant
cost is that the return can go back to many places.  Since any program has
a finite number of places that a procedure can return to you can emulate
this with a decision tree; however the cost of executing the tree increases
with program size (actually number of return points.)

On the other hand procedure call/return is not as strong as computed goto
(transfer to stored address which may be altered.)  The proof is a little
tricky; however the fundamental point is that the call part is a transfer
to a fixed address.
-- 

In the fields of Hell where the grass grows high
Are the graves of dreams allowed to die.
	Richard Harter, SMDS  Inc.