Skip to content
Prev 35503 / 63424 Next

iterative list rm [Was: R-devel Digest, Vol 83, Issue 2]

On Jan 2, 2010, at 5:41 PM, Romain Francois wrote:

            
That blows up if the object is the first in the list BTW. You probably meant more something like

static SEXP ReleaseObj(SEXP object, SEXP list) {
	if (!isNull(list)) {
		if (CAR(list) != object) {
			SEXP c = list;
			while (!isNull(CDR(c))) {
				if (CADR(c) == object) {
					CDR(c) = CDDR(c);
					break;
				}
				c = CDR(c);
			}
		} else return CDR(list);
	}
	return list;
}
		
(For non-core replace CDR(c) with SETCDR(c) although that goes through the write barrier).

Cheers,
Simon