On Fri, Mar 21, 2008 at 09:00:17PM -0400, "alexmv@mit.edu via RT" <bug-Coro@rt.cpan.org> wrote:
Show quoted text> Did even run the test I attached?
No, I only read it carefully, is running it necessary to understand your
problem (that would imply that your comments about it were wrong...)?
Show quoted text> It does *not* work exactly as
> documented by perl, because perl only has one call stack at once.
The number and existance of a call stack is irrelevant, as local is
not defined in relation to any call stack, it simply creates a dynamic
binding.
The only stack involved is the one local uses, and there is only one, with
coro, or without, and the behaviour is the same.
Show quoted text> Coro allows multiple call stacks, and thus local's behavior is less well
> defined
local's behaviour is well-defined with or without Coro, and it works the
same. The fact that you don't understand what local does (and likely
confuse it with my) is of little relevance.
Show quoted text> "leaving a block" could be construed to incude cede'ing to
> other coroutines
No, leaving a block means leaving a block. If you "incude" anything that
is only in your mind, Coro neither does that, nor implies that, nor
documents that, nor aims for that: Leaving a block simply means leaving a
block, and nothing else.
Show quoted text> which would imply that local'd values would be part of
> per-coroutine state, in addition to the call stack.
If you start with obviously wrong statements you can derive anything out
of them, so thats true. If I were the emperor of china...
Show quoted text> Regardless, Coro allows blocks to be exited in an order other than the
> order in which they were entered
Yes.
Show quoted text> which can restore the wrong values from the stack
No. It will always restore the correct value. local introduces a _dynamic_
binding, not a lexical one, as you assume.
Please take a good book about perl, which will immediately teach you that
local will _not_ create local variables as you assume, and that you need
to use my for that.
Coro doesn't change that, you are just more surprised by your lack of
understanding.
Use "my", that is creating local variables, and works as you expect. local
does something completely different, and what you apparently want cannot
be implemented with it, as it simply isn't creating any local variable or
scoped binding of any kind. You really want my, and this is completely
independent of Coro.
Show quoted text> In the test I attached, the value of $thing at the end
> of the program is 3 -- but, given a different ordering of coroutines
> exiting the local'd block, it could be anything between undef and 3.
> This is extremely non-intuitive.
local is extreemly unintuitive, because beginner programmers usually think
it has something to do with local variables, which it doesn't have.
Show quoted text> Does this clarify the issue at all?
Yes, of course, it was completely clear to me before, too: You confuse
local with the notion of local variables, a typical programmers error. You
go farther in confusing the implied stack local uses with any call stack
(which is not the case, and never was, regardless of how many call stacks
are available).
This is fine (being a typical beginners mistake), but please fetch yourself a
book that explains the semantics of local vs. my and use my until you
understand what local does. And please stop abusing the bugtracker, I am
certainly more open to discuss this privately and teach you about local when
I do not have to care for the bugtracker.
The bugtracker is not a place to ask programming questions.
--
The choice of a Deliantra, the free code+content MORPG
-----==- _GNU_
http://www.deliantra.net
----==-- _ generation
---==---(_)__ __ ____ __ Marc Lehmann
--==---/ / _ \/ // /\ \/ / pcg@goof.com
-=====/_/_//_/\_,_/ /_/\_\