Alex Tweedly wrote:

You need to be careful (i.e. precise) when you say that :-)
   send "xxx" to me in N ticks
is kind of like a (delayed) goto - the message is queues, then the code following the 'send'; statement is executed (so it's not really quite like a GOTO), and when the handler (and any calling handlers) exits, or a "wait with messages or other 'send in time' statement is executed) then the message queue will send the message

On the other hand,
  send "xxx" to me
is just not at all like a GOTO. The handler is executed immediately (via the message passing), but THEN the following code is also executed - so it's very like a GOSUB, and therefore very, very like just using the handler name directly; basically the only difference seems to be that it's less efficient.

So if you were doing simply 'send "xxx" to me' then you would still be building up a stack of calls; we can argue semantics whether it is officially called "recursion" or not - but the effect would be that all of these would have context that needs to be kept simultaneously.

Hmmm - not easy to follow what I wrote there - try this concrete example instead : The following 3 code samples differ *only* in the recursive call / send statement.

on subCheckNow
    -- do stuff here
    if lCounter > 3 then exit subCheckNow
    add 1 to lCounter
    put "before" & cr after field "F"
    send "subCheckNow" to me
put "after" & cr after field "F" end subCheckNow

and ALSO

on subCheckNow
    -- do stuff here
    if lCounter > 3 then exit subCheckNow
    add 1 to lCounter
    put "before" & cr after field "F"
    subCheckNow
put "after" & cr after field "F" end subCheckNow


BOTH produce

before
before
before
before
after
after
after
after


But in contrast,

on subCheckNow
    -- do stuff here
    if lCounter > 3 then exit subCheckNow
    add 1 to lCounter
    put "before" & cr after field "F"
    send "subCheckNow" to me in 1 tick
put "after" & cr after field "F" end subCheckNow

produces

before
after
before
after
before
after
before
after


--
Alex Tweedly       http://www.tweedly.net



--
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.1.394 / Virus Database: 268.9.9/382 - Release Date: 04/07/2006

_______________________________________________
use-revolution mailing list
[email protected]
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution

Reply via email to