Re[2]: Re: New stackless proposal
Lenard Lindstrom <[email protected]>
| Newsgroups | gmane.comp.lang.prothon.user |
|---|---|
| Message-ID | <Mahogany-0.66.0-4294680211-20040711-202358.00@pop3.norton.antivirus> |
On Sun, 11 Jul 2004 16:51:40 -0700 Paul Prescod <[email protected]> wrote: > Mark Hahn wrote: > > >... > >>I notice you use a wrapping model here rather than an inheritance > >>model (opposite of properties). OSThread looks like a wrapper. > > > > > > It is an inheritance model. > > I see nothing in the example to indicate that OSThread inherits from > thread1 or vice versa. > > > ... It just happens to reuse the thread1 binding. > > Can you see how that makes it more difficult to read the code? > > >>I don't understand why you use call_ to arm a thread and then rebind > >>the name. If the call_ function mutates the underlying object then > >>why do > >>you have to rebind the name? > > > > > > That is a mistake. I will change it to remove the assignment: > > > > thread1(10) # call thread1 to "arm" it > > I think using call_ for this is confusing. If you really feel like you > have to use call_ it would be a lot more clear to use it for starting. > But perhaps better not to use it at all. > > thread1.setParams(10) > thread1.start() > > Explicit is better than implicit! > call_ is for generator compatibility. It is awkward but allows threads to be used to construct generators. # Define function for generator. It is just another Func. def myrange(n): # return 0..(n-1) for i in n: yield(i) # just another function call # Make myrange a thread. Now it can be a generator (coroutine). generator = Thread(generator) # Arm myrange with argument 5 and call its iter_ method to create an # iterator that coordinates with the generator's yield() function # calls. for x in myrange(5): print(x) Then again, with decorators: (Thread) def myrange(n): ... Lenard Lindstrom <[email protected]>