Javascript vs. Lua (23)

19 Name: #!/usr/bin/anon 2006-02-21 04:09 ID:dBFyrEhb

Isn't that a generator? A coroutine is where you have some number of functions A,B... and they can jump inside each other arbitrarily, like this:
A
|
|-jump!-B

    |
|
|

|-------+ #back to A
|
|

In ye olden days coroutines were used to make lightweight thread-style code, e.g. A is the user (gets input), and B is an AI player. They are still good for making lightweight threads withouot relying on external libraries or loljava.

Incidentally. python wins:
def func():

i=0
while i<10:
yield i
i+=1

(or, since we aren't passing any arguments, this works too:)
(i for in in range(10))
or, come to think of it, xrange(10) works too, but that doesn't explain anything.

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