// A C++ version of the LISP LENGTH Function. // // File: length.cc // Author: course // Version: 1 #include "lisp.h" // Returns the length of a list. Calls error for dotted // lists. // int length (object * list) { int len = 0; cons * clist; while (clist = may_be_cons (list)) { len++; list = cdr (clist); } if ( ! null (list)) error ( "LENGTH: Unexpected dot construction: ", list ); return len; }