\cdbalgorithm{length}{}

Replaces the expression with its length, that is, the number of terms
in a sum, the number of factors in a product or the number of
elements in a list.
\begin{screen}{1,2,4,5,7,8}
lst:= {a,b,c,d}:
@length(%);
lst:= 4;
sum:= a + b + c + d + e:
@length(%);
sum:= 5;
prod:= a*b*c:
@length(%);
prod:= 3;
\end{screen}
Note that the original expression gets replaced; if you need a new
expression use a square-bracket construction as in
\begin{screen}{1,2}
sum:= a + b + c + d;
@length[@(sum)];
2:= 4;
\end{screen}

Here is a more complicated example which takes all terms except the
first and last from an expression:
\begin{screen}{1,2}
a+b+c+d+e+f+g;
@take(%){ 1..@collect_terms[@length[@(%)]-2] };
b+c+d+e+f;
\end{screen}
(remember that counting terms starts from zero).

If you just want to display the number of elements, use
\subscommand{number\_of\_terms}; this is an output command and does
not change the expression.

\cdbseealgo{number_of_terms}
\cdbseealgo{take_match}
