# Count how many atoms, numbers, constant, variable, simple term, and complex term in the list

**URL:** <https://swi-prolog.discourse.group/t/count-how-many-atoms-numbers-constant-variable-simple-term-and-complex-term-in-the-list/4613>\
**Category:** Help!\
**Tags:** how-to\
**Created:** [October 29, 2021, 6:45pm UTC](https://swi-prolog.discourse.group/t/count-how-many-atoms-numbers-constant-variable-simple-term-and-complex-term-in-the-list/4613 "2021-10-29T18:45:33Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Azrael](https://avatars.discourse-cdn.com/v4/letter/a/f6c823/32.png) [@Azrael](https://swi-prolog.discourse.group/u/Azrael)\
**Post date:** [October 29, 2021, 6:45pm UTC](https://swi-prolog.discourse.group/t/count-how-many-atoms-numbers-constant-variable-simple-term-and-complex-term-in-the-list/4613/1 "2021-10-29T18:45:33Z")

</div>

I’m using: SWI-Prolog online version

I want the code to: count how many atoms, numbers, constant, variable, simple term, and complex term in the list.

Example :

```prolog
?- term_count([2,[a],A,32,c,2.3,hi,;,_,1],Atm,Num,Con,Var,Sim,Com).
Atm=3,
Num=4,
Con=7,
Var=2,
Sim=9,
Com=1

```

But what I’m getting is: error. I already changes it many times, but it doesn’t work

My code looks like this:

```prolog
term([],_,_,_,_,_,_,_,;,_,_).
term([H|T],A,_,_,_,_,_,_,;,_,_):-atom(H),term(T,A1,_,_,_,_,_,_,;,_,_),A1 is A+1.
term([H|T],_,B,_,_,_,_,_,;,_,_):-number(H),term(T,_,B1,_,_,_,_,_,;,_,_),B1 is B+1.
term([H|T],_,_,C,_,_,_,_,;,_,_):-atomic(H),term(T,_,_,C1,_,_,_,_,;,_,_),C1 is C+1.
term([H|T],_,_,_,D,_,_,_,;,_,_):-var(H),term(T,_,_,_,D1,_,_,_,;,_,_),D1 is D+1.
term([H|T],_,_,_,_,E,_,_,;,_,_):-atomic(H),term(T,_,_,_,_,E1,_,_,;,_,_),E1 is E+1.
term([H|T],_,_,_,_,_,F,_,;,_,_):-complexTerm(H),term(T,_,_,_,_,_,F1,_,;,_,_),F1 is F+1.
term([H|T],_,_,_,_,_,_,G,;,_,_):-atom(H),term(T,_,_,_,_,_,_,G1,;,_,_),G1 is A1+1.
term([H|T],_,_,_,_,_,_,_,;,_,I):-number(H),term(T,_,_,_,_,_,_,_,;,_,I1),I1 is B1+1.
complexTerm(X):- nonvar(X), functor(X,_,A), A > 0.

```

Please help me… Thx
