+struct ao_scheme_cons *
+ao_scheme_cons_copy(struct ao_scheme_cons *cons)
+{
+ struct ao_scheme_cons *head = NULL;
+ struct ao_scheme_cons *tail = NULL;
+
+ while (cons) {
+ struct ao_scheme_cons *new;
+ ao_poly cdr;
+
+ ao_scheme_cons_stash(cons);
+ ao_scheme_cons_stash(head);
+ ao_scheme_cons_stash(tail);
+ new = ao_scheme_alloc(sizeof (struct ao_scheme_cons));
+ tail = ao_scheme_cons_fetch();
+ head = ao_scheme_cons_fetch();
+ cons = ao_scheme_cons_fetch();
+ if (!new)
+ return AO_SCHEME_NIL;
+ new->car = cons->car;
+ new->cdr = AO_SCHEME_NIL;
+ if (!head)
+ head = new;
+ else
+ tail->cdr = ao_scheme_cons_poly(new);
+ tail = new;
+ cdr = cons->cdr;
+ if (!ao_scheme_is_cons(cdr)) {
+ tail->cdr = cdr;
+ break;
+ }
+ cons = ao_scheme_poly_cons(cdr);
+ }
+ return head;
+}
+