# Efficient append of N lists after N findall calls

**URL:** <https://swi-prolog.discourse.group/t/efficient-append-of-n-lists-after-n-findall-calls/4702>\
**Category:** Help!\
**Created:** [December 2, 2021, 6:31am UTC](https://swi-prolog.discourse.group/t/efficient-append-of-n-lists-after-n-findall-calls/4702 "2021-12-02T06:31:41Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![grossdan](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/grossdan/32/23_2.png) [@grossdan](https://swi-prolog.discourse.group/u/grossdan)\
**Post date:** [December 2, 2021, 6:31am UTC](https://swi-prolog.discourse.group/t/efficient-append-of-n-lists-after-n-findall-calls/4702/1 "2021-12-02T06:31:41Z")

</div>

Hello,

Suppose you have a predicate that in its body has 5 findall calls, one performed after the other leading to 5 lists, Now suppose you want to append those 5 lists as a result of the predicate.

One can write four appends to combine them all and return the combined list. I wonder what the most efficient way to combine such N lists are.

I am wondering if one can do better, somehow, than simply appending them, e.g. with difference lists, altough each list is generated by findall…

Perhaps best if there was a findall version that generates a difference list as a result …

thanks,

Dan

---

<div class="post-metadata">

**Author:** ![EricGT](https://avatars.discourse-cdn.com/v4/letter/e/f1d935/32.png) [@EricGT](https://swi-prolog.discourse.group/u/EricGT)\
**Post date:** [December 2, 2021, 7:16am UTC](https://swi-prolog.discourse.group/t/efficient-append-of-n-lists-after-n-findall-calls/4702/2 "2021-12-02T07:16:33Z")

</div>

If you want findall with open list (difference list) then consider findall/4.

Can your list be converted to a set?  
If so then consider ord\_union/2.

---

<div class="post-metadata">

**Author:** ![grossdan](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/grossdan/32/23_2.png) [@grossdan](https://swi-prolog.discourse.group/u/grossdan)\
**Post date:** [December 2, 2021, 7:50am UTC](https://swi-prolog.discourse.group/t/efficient-append-of-n-lists-after-n-findall-calls/4702/3 "2021-12-02T07:50:49Z")

</div>

Thanks!,

I never knew that findall has a difference list version – thank you for pointing this out to me …

i should have re-checked in the docu 🙂
