# Determine the length of the list

There is a recursive method:

```(nil  defmethod len ()  0)
('cons  defmethod len ()
(1  + ((this  rest) len)))```

In these simple tasks is unprofitable to use recursion, because the result is the excessive use of stack memory for the return of function. Use the variable.

```(nil  defmethod len ()
(nil  let ((i this) (l  (0  copy)))
(nil  while (nil  consp i)
(nil  parallel
(nil  setq  i (i  rest))
(l  +=  1)))
l))```

Lists may not be linear and looped. In such circumstances, the program will loop so as not to be overseen by the possibility of cycles. The complexity of the algorithm will be O(n²).

```(nil  defmethod len ()
(nil  let ((last  this) (lastnext (this rest))  (l  (0  copy))  (flagcycled false))
(nil  while (nil  and (nil  consp last) (nil  not flagcycled))
(nil  parallel
(nil  if  (lastnext find  this  last)
(nil  setq  flagcycled  true)
(nil  setq  last  lastnext  lastnext  (lastnext rest)))
(l  +=  1)))
l))
(nil  defmethod find  (first  last)
(nil  let ((flagfound false))
(nil  while (nil  and (nil  not (nil  eq  first last))  (nil  not flagfound))
(nil  if  (nil  eq  this  first)
(nil  setq  flagfound true)
(nil  setq  first (first  rest))))
(nil  if  (nil  not flagfound)
(nil  if  (nil  eq  this  first)
(nil  setq  flagfound true)))
flagfound))```

Using sophisticated algorithms, the complexity of O(n²) is a restricted area for programmers. Such situations are avoided. Rotating list is essentially a graph (math.). The graph has no concept of length, but there are the number of items. In graphs nobody counts the elements.
The list is a complex object of several elements, every self-respecting programmer has a variable length.