[chuck-users] Passing classes to functions

Adam Tindale adamtindale at hotmail.com
Sat Oct 3 20:21:59 EDT 2009


Hi Everyone,

This is a more direct version of what I meant to say. The problem I
encountered was that I was hoping to do some operations in a function
and was hoping that I was passing a copy of an object, much like what
happens with primitives. Since objects pass by reference then weird
side effects and bugs can easily creep into a fellow ChucKist's code.

As for the manual... it is badly out of date. I have been talking with
Ge about unifying the docs and making contributions from the list
easier to integrate. The mailing list is an incredible wealth of
knowledge, but hard to parse for the new ChucKist. I'm hoping to
organize a documentaiton sprint around Christmas when some more of
these hack pacts are done, so we can integrate some of the great
things coming out of that.

Anyways, I hope this example is more clear.

--art

class test{
    0 => int val;
}

test obj1;
<<< obj1.val , "original object">>>;

fun void testclasspassing(test i)
{
    4 => i.val;
    <<< i.val, "in function" >>>;
    // side effect!
}

testclasspassing(obj1);
<<< obj1.val , "original object">>>;


More information about the chuck-users mailing list