public static int length(Object x) { int len = 0; while (x is Pair) { len++; x = ((Pair)x).rest; } return len; }