+.sub main :main
+ .local string ok, not_ok
+ ok = "ok"
+ not_ok = "not ok"
+ # if 'not ok' is printed, it means that the lexical environment
+ # for the first closure in each pair, (where "out" = "ok")
+ # was overwritten by the lexical environment created for the
+ # second closure (where "out" = "not ok")
+ $P10 = makebar_clone(ok)
+ $P20 = makebar_clone(not_ok)
+ .param pmc out
+ .lex 'out', out
+ .const .Sub s = 'bar'
+ $P0 = clone s
+.sub bar :outer(makebar_clone)
+ $P0 = find_lex 'out'
+ say $P0
(This prints "not ok". The test in the patch expects "ok".)
You're arguing that the different copies of "bar" that are returned from makebar_clone
should have different lexical environments. I'm pretty sure that this is not the case. Without
using "newclosure", there's no closure so the lexical environments are the same.
What the :outer does in this case is rearrange the lexical stack so that "makebar_clone"
appears in the lexical stack for "bar". So we're using the lexical environment from the last
time that "makebar_clone" was called. It's bizarre that this even works because without the
closure, I'd think that the lexical environment would have destroyed.
I'm not sure how intentional this is. The PDD isn't clear (to me) about what :outer means in
the absence of "newclosure". I'd definitely be interested in seeing why this would be a useful
feature. More detail in the PDD would be nice.
Thanks for the interesting patch.
> Now it makes sense. :) Anyway, I found this by following the Compiler FAQ,
> which says that a new closure should be created by cloning the sub. I
> it should be changed to say newclosure, or even explain this (because you
> might really want to clone the Sub in some cases.)
in r21136 I have changed compiler_faq.pod, so that it now uses
'newclosure' instead of 'clone'.
More explanation could also be added to 'examples/tutorial/80_closure.pir'.
As the original issue has been clarified, can I close this ticket?
/* Bernhard.S...@gmx.de */
> As the original issue has been clarified, can I close this ticket?
Since no one has suggested otherwise since September, I'll close it for