# Add the element to the list, if it passes the test

**URL:** <https://swi-prolog.discourse.group/t/add-the-element-to-the-list-if-it-passes-the-test/3122>\
**Category:** Help!\
**Created:** [October 30, 2020, 11:50pm UTC](https://swi-prolog.discourse.group/t/add-the-element-to-the-list-if-it-passes-the-test/3122 "2020-10-30T23:50:00Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![PrologAxel](https://avatars.discourse-cdn.com/v4/letter/p/ad7895/32.png) [@PrologAxel](https://swi-prolog.discourse.group/u/PrologAxel)\
**Post date:** [October 30, 2020, 11:50pm UTC](https://swi-prolog.discourse.group/t/add-the-element-to-the-list-if-it-passes-the-test/3122/1 "2020-10-30T23:50:00Z")

</div>

I’m using: SWI-Prolog version 8.2.1

Hello.

% V Head of list is send to testing. If it gets approved, then append gets it.

```prolog
goThrougList([V|R], Z) :- 
   goThrougList(R, D), 
   testing([V], Q), 
   append(D,[Q],Z).

testing(S, T) :- 
   phrase(as, [S], []), 
   append([],[S],T).

```

% Here is the problem. Only if phrase(as, [S], []) is true,  
only then S should be allowed to be added to the list.  
And then the element, as Q, should be given to the append in the third line.

Start the program:

```prolog
starting("someText(_15188,_15190,[_15136|_15138],[_15136|_15178]):- 
  dif(_15188,_15136),
  someText(_15188,_15190,_15138,_15178)", Cs).

```

The result ist:

```prolog
Cs = [[[')']], [['8']], [['7']], [['1']], [['5']], [['1']], [['_']], [[...]], [...]|...] 

```

But I want the result:

```prolog
Cs = [[['8']], [['7']], [['1']], [['5']], [['1']], [['_']], [[...]], [...]|...] 

```

(I want only the numbers and only ‘\_’, but not ‘)’ etc.)

Thank you

My code looks like this:

```prolog
starting(Q, W) :- atom_codes(A, Q), atom_chars(A, Cs), goThrougList(Cs, W).

goThrougList([], []).
goThrougList([V|R], Z) :- goThrougList(R, D), testing([V], Q), append(D,[Q],Z).

testing(S, T) :- phrase(as, [S], []), append([],[S],T).

as --> [].
as --> [0], as.
as --> [1], as.
as --> [2], as.
as --> [3], as.
as --> [4], as.
as --> [5], as.
as --> [6], as.
as --> [7], as.
as --> [8], as.
as --> [9], as.
as --> [0], as.
as --> [_], as.

```

---

<div class="post-metadata">

**Author:** ![PrologAxel](https://avatars.discourse-cdn.com/v4/letter/p/ad7895/32.png) [@PrologAxel](https://swi-prolog.discourse.group/u/PrologAxel)\
**Post date:** [November 1, 2020, 9:09am UTC](https://swi-prolog.discourse.group/t/add-the-element-to-the-list-if-it-passes-the-test/3122/2 "2020-11-01T09:09:46Z")

</div>

Solved. I used member and not(member.
