Javascript vs. Lua (23)

16 Name: #!/usr/bin/anon 2006-01-17 16:00 ID:kdUZ8Jcm

Coroutines are a generalization of subroutines, allowing one routine to consume as input the output of another routine. Imagine that in C you could write:

int function(void)
{
int i;
for (i = 0; i < 10; i++)
return i;
}

and successive calls to the function would return 0 through 9. That C code doesn't really work, but this is what coroutines let you do. See also:

http://www.chiark.greenend.org.uk/~sgtatham/coroutines.html
http://www.lua.org/manual/5.0/manual.html#2.10
http://www.lua.org/pil/9.html

Another cool language supporting coroutines is Icon, http://www.cs.arizona.edu/icon/. Lua's coroutines were inspired by Icon, I think.

This thread has been closed. You cannot post in this thread any longer.