# Removing elements from a list: select/3 behaves differently than nth1/4

**URL:** <https://swi-prolog.discourse.group/t/removing-elements-from-a-list-select-3-behaves-differently-than-nth1-4/4604>\
**Category:** Discussion\
**Created:** [October 28, 2021, 8:48am UTC](https://swi-prolog.discourse.group/t/removing-elements-from-a-list-select-3-behaves-differently-than-nth1-4/4604 "2021-10-28T08:48:49Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![JCR](https://avatars.discourse-cdn.com/v4/letter/j/258eb7/32.png) [@JCR](https://swi-prolog.discourse.group/u/JCR)\
**Post date:** [October 28, 2021, 8:48am UTC](https://swi-prolog.discourse.group/t/removing-elements-from-a-list-select-3-behaves-differently-than-nth1-4/4604/1 "2021-10-28T08:48:49Z")

</div>

Hi community,  
I am a bit confused why in `test7` i get a second solution in which `IN` is` [p(A), p(A)]`. This does not happen with nth1/4 as shown in `test8`. Does select/3 somehow unify `p(A)` and `p(B)`?  
Cheers/JCR

```prolog
test7:- 
    IN = [p(A), p(B)], 
    select(p(A), IN, OUT),
    numbervars(IN, 0, _),
    numbervars(OUT, 0, _),
    format('~w~w~n', ['IN is ', IN]),
    format('~w~w~n', ['OUT is ', OUT]).

test8:-
    IN = [p(A), p(B)],
    between(1, 2, IND),
    nth1(IND, IN, _, OUT),
    numbervars(IN, 0, _),
    numbervars(OUT, 0, _),
    format('~w~w~n', ['IN is ', IN]),
    format('~w~w~n', ['OUT is ', OUT]).

```

OUTPUT:

```prolog
?- test7.
IN is [p(A),p(B)]
OUT is [p(B)]
true ;
IN is [p(A),p(A)]
OUT is [p(A)]
true.

```

```prolog
?- test8.
IN is [p(A),p(B)]
OUT is [p(B)]
true ;
IN is [p(A),p(B)]
OUT is [p(A)]
true.

```

---

<div class="post-metadata">

**Author:** ![jan](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jan/32/4_2.png) [@jan](https://swi-prolog.discourse.group/u/jan)\
**Post date:** [October 28, 2021, 1:41pm UTC](https://swi-prolog.discourse.group/t/removing-elements-from-a-list-select-3-behaves-differently-than-nth1-4/4604/2 "2021-10-28T13:41:17Z")

</div>

> [@JCR](#):
>
> ```prolog
> IN = [p(A), p(B)], 
> select(p(A),
> 
> ```

As the A in select shares with the A of the first element, selecting p(B) unifies A with B.

---

<div class="post-metadata">

**Author:** ![JCR](https://avatars.discourse-cdn.com/v4/letter/j/258eb7/32.png) [@JCR](https://swi-prolog.discourse.group/u/JCR)\
**Post date:** [October 28, 2021, 2:01pm UTC](https://swi-prolog.discourse.group/t/removing-elements-from-a-list-select-3-behaves-differently-than-nth1-4/4604/3 "2021-10-28T14:01:41Z")

</div>

Thanks @jan! Now i understand.
