Forums before death by AOL, social media and spammers... "We can't have nice things"
|    comp.os.vms    |    DEC's VAX* line of computers & VMS.    |    264,096 messages    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
|    Message 264,014 of 264,096    |
|    =?UTF-8?Q?Arne_Vajh=C3=B8j?= to All    |
|    Re: New PHP kits available (and a progra    |
|    02 Jan 26 14:45:47    |
   
   From: arne@vajhoej.dk   
      
   On 1/1/2026 10:44 PM, Lawrence D’Oliveiro wrote:   
   > On Thu, 1 Jan 2026 20:51:57 -0500, Arne Vajhøj wrote:   
   >   
   >> function test($v) {   
   >> echo "B1 ($v)\n";   
   >> $v = Fiber::suspend(123);   
   >> echo "B2 ($v)\n";   
   >> $v = Fiber::suspend(456);   
   >> echo "B3 ($v)\n";   
   >> return 789;   
   >> }   
   >>   
   >> echo "A1\n";   
   >> $ctx = new Fiber('test');   
   >> $v = $ctx->start('ABC');   
   >> echo "A2 ($v)\n";   
   >> $v = $ctx->resume('DEF');   
   >> echo "A3 ($v)\n";   
   >> $v = $ctx->resume('GHI');   
   >> if($v === null) $v = $ctx->getReturn();   
   >> echo "A4 ($v)\n";   
   >   
   > Python version (produces same sequence of output values):   
   >   
   > def test(v) :   
   > print("B1", v)   
   > v = yield 123   
   > print("B2", v)   
   > v = yield 456   
   > print("B3", v)   
   > return 789   
   > #end test   
   >   
   > try :   
   > print("A1")   
   > coro = test("ABC")   
   > v = coro.send(None)   
   > print("A2", v)   
   > v = coro.send("DEF")   
   > print("A3", v)   
   > v = coro.send("GHI")   
   > except StopIteration as ret :   
   > print("A4", ret.value)   
   > #end try   
   >   
   > Note this doesn’t even need a coroutine function (async def); a simple   
   > generator will do.   
      
   PHP has generators as well.   
      
   The above could be done as:   
      
   current();   
   echo "A2 ($v)\n";   
   $ctx->send('DEF');   
   $v = $ctx->current();   
   echo "A3 ($v)\n";   
   $ctx->send('GHI');   
   $v = $ctx->getReturn();   
   echo "A4 ($v)\n";   
      
   ?>   
      
   But fibers/kp is operating at a much lower level   
   than generators that are just syntactic sugar for   
   an object with methods.   
      
   I am not sure that it matters much for Python or PHP,   
   but in C it is an entirely different execution context.   
      
   Arne   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   
|
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
(c) 1994, bbs@darkrealms.ca