[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: cyclic



Rewrite your example and you'll get the behavior you expect:

Foo: adt{
        link: cyclic ref Foo;
        i: int;
};

        foo := ref Foo(nil, 0);
        bar := ref Foo(nil, 1);
        foo.link = bar;
        bar.link = foo;

You had instead

        foo := Foo(nil, 0);
        bar := Foo(nil, 1);
        foo.link = ref bar;
        bar.link = ref foo;

which doesn't work because, as you said, "ref X" makes a reference
to a copy of X.  The problems you're seeing aren't because of the
'cyclic' keyword but a misunderstanding of 'ref'.

-rob