On Nov 30, 2004, at 11:45 AM, Dan Sugalski wrote:

In this example:

% cat continuation6.ruby
def strange
    callcc {|continuation| $saved = continuation}
end

def outer
    a = 0
    strange()
    a = a + 1
    print "a = ", a, "\n"
end

Through the joys of reference types, a will continue to increase forevermore, assuming the compiler hasn't incorrectly put a in an int register. (Which'd be wrong)

Separate question, but then what would happen for languages which _do_ use primitive types? (Presumably, Perl6 would do that in the "my int" case.) If proper behavior requires basically never using the primitive I/N types, that seems like a waste.


Remember the PMC and string registers hold pointers to pmc/string structures, which is all we're preserving -- the *pointer* to the structure, not the contents of the structure.

Sure.

The contents can change over and over without the register itself ever changing.

But in this Ruby case, "a = a + 1" actually creates a new Fixnum instance, so "a" ends up holding a different instance each time--you can verify that by printing out a.id in the print statement. (And if you don't like that, you can get the effect I'm talking about with an a = MyCustomClass.new(a.int_value() + 1) sort of thing.)


So it would seem that what you are saying only works if the register isn't holding the Fixnum instance, but instead is holding some RubyReference instance which references the Fixnum instance. But that seems like a needless extra object, in the lexical variable case. (I could see having the intervening object in the global case, to avoid repeated hash lookups.)

JEff



Reply via email to