Cons in Java


Method Summary
static Cons cons(Object x, Cons y)
           Returns a new Cons cell whose first is x and whose rest is y.
           Cons is the data type; cons() is the method that makes a new Cons cell and puts two pointers into it.
           cons("a", null) = (a)
           cons puts a new thing on the front of an existing list:
           cons("a", list("b","c")) = (a b c)
           cons(list("a"), list("b","c")) = ((a) b c)
static Object first(Cons x)
           Returns the first thing in a list:
           first(list("a", "b", "c")) = "a"
           first(list(list("a", "b"), list("c", "d"))) = (a b)
           As a convenient safety feature, first(null) = null
static Cons rest(Cons x)
           Returns the rest of a list after the first thing.
           rest(list("a", "b", "c")) = (b c)
           rest(list(list("a", "b"), list("c", "d"))) = ((c d))
           As a convenient safety feature, rest(null) = null
static boolean consp(Object x)
           Returns true if x is a Cons, false if x is null or not a Cons.
static Object second(Cons x)
           Returns the second thing in a list:
           second(list("+", "b", "c")) = "b"
static Object third(Cons x)
           Returns the third thing in a list:
           third(list("+", "b", "c")) = "c"
static void setfirst(Cons x,  Object  i)
           Do not use setfirst in class assignments.
           Destructively changes the first of x to be i.
           setfirst(list("a", "b", "c"), 3) = (3 b c)
static void setrest(Cons x,  Cons  y)
           Do not use setrest in class assignments.
           Destructively changes the rest of x to be y.
           setrest(list("a", "b", "c"), null) = (a)
           setrest(list("a", "b", "c"), list("d","e")) = (a d e)
static Cons list(Object x1, ... , xn)
           Returns a list of the items x1 through xn.
           list() = null
           list("a", "b", "c") = (a b c)
static String toString(Cons x)
           Returns a string that represents the argument x in parenthesized list notation.
static int length(Cons x)
           Returns the top-level length (number of Cons cells) of a list:
           length(list("a", "b", "c")) = 3
           length(list(list("a", "b"), list("c", "d"))) = 2
           length(null) = 0
static Cons append(Cons x,  Cons y)
           append copies its first argument list and appends the second argument list, leaving the arguments unchanged.
           append(list("a", "b", "c"), list("d", "e")) = (a b c d e)
static Cons nconc(Cons x,  Cons y)
           Do not use nconc in class assignments.
           nconc destructively puts the second argument list onto the end of the first argument list, changing its first argument.
           x = list("a", "b", "c");
           y = list("d", "e");
           nconc(x, y) = (a b c d e) and also x = (a b c d e) afterwards.
           Always save the result of nconc in case the first argument was null, e.g.:
           lst = nconc(lst, z);
static Cons reverse(Cons x)
           Returns a reversed copy of the top level of the argument list:
           reverse(list("a", "b", "c")) = (c b a)
           reverse(list(list("a", "b"), list("c", "d"))) = ((c d) (a b))
static Cons nreverse(Cons x)
           Returns a destructively reversed copy of the top level of the argument list.
           Always save (return or assign to a variable) the result of nreverse.
           A legitimate way to use nreverse is to reverse the result of a list that is constructed backwards:
           for ( ... )
               result = cons(item, result);
           return nreverse(result);