r0 on a mixed list

i had always thought that a list (xt==0) held a reference to its elements.  i expected that if xr==0, then r0(x) would also r0() each of it’s elements.

does the programmer have to recurse through a mixed list, calling r0() on each item?

do i need something like this:?

V r9(K x){if(!xr){if(!xt)DO(xn,r9(xK[i]))else r0(x);}}

this program (gcc p.c -o p -g3 -DKXVER=3 -pthread l64/c.o)

shows that, given a list (constructed with knk), with elements with zero xr, the elements are not r0()'ed.

#include<stdio.h>

#include"k.h"

#define O3 DO(3,O(“%d;”,k[i]->r))O(“\n”)


I main(){khp(“”,0);K k[3];DO(2,k[i]=kj(i));k[2]=knk(2,k[0],k[1]);

O3;

r0(k[2]);

k[1]->j=99;

O3;

r0(k[1]);

O3;

R 0;}

>if xr==0, then r0(x) would also r0() each of it’s elements.

yes

>does the programmer have to recurse through a mixed list, calling r0() on each item?

no

knk does not increment ref count on args, so the error in your example is that you use k[0] twice but have only one ref count each for the shared objects.

fix with

k[2]=knk(2,r1(k[0]),r1(k[1]));

ref counts do not get decremented below zero. To be able to observe decrements, ensure the count is > 0.

Simplified example

I main(){

 khp(“”,0);

 K x=kj(0),y=knk(1,r1(x));

 printf(“%d\n”,x->r);

 r0(y);

 printf(“%d\n”,x->r);

 R 0;

}