On Apr 7, 2008, at 10:28 PM, Dan Amelang wrote:

The reuse of the parameter value was
throwing me off. Seeing the same memory address casted two different
ways and overriding itself all in one line was bizarre for me.
But to each his own.

FWIW, here's the rationale behind the way the code is written.

        Array size_: _size value_: _value
        [
            self := self new: (SmallInteger value_: _size).

Let's just ignore the fact that new storage is allocated here -- it's irrelevant to the alias and casting that is proving to be so confusing.

            _oops := _value.

That line says: "the contents of the new object share space with the template contents generated by the Compiler." (1)

            {
              int i;
              for (i= 0;  i < (int)v__size;  ++i)
                ((oop *)self->v__oops)[i]= *((oop **)v__value)[i];

That loop says: "the contents of the new object are derived from the template contents by indirecting through each entry in the template." (2)

            }.
        ]

The reason why it seems right (to my Pooh Bear brain) to express it that way is that the two statements (1) and (2) are independent. (1) tells you where the storage '_oops' comes from and (2) tells you how each element of the new object 'v__oops[]' is related to the corresponding element in the template 'v__value[]' emitted by the compiler. As it is written the loop is agnostic about whether or not the contents of the new Array share storage with the template generated by the Compiler. If you were to replace v__value by v__oops in (2) then the code would break in one of the two cases.

Bye,
Ian


_______________________________________________
fonc mailing list
[email protected]
http://vpri.org/mailman/listinfo/fonc

Reply via email to