Copy Tree and Substitute in Java
public static Object copy_tree(Object tree) { if ( consp(tree) ) return cons(copy_tree(first((Cons) tree)), (Cons) copy_tree(rest( (Cons) tree))); return tree; } public static Object subst(Object gnew, String old, Object tree) { if ( consp(tree) ) return cons(subst(gnew, old, first((Cons) tree)), (Cons) subst(gnew, old, rest((Cons) tree))); return (old.equals(tree)) ? gnew : tree; }