# List manipulation when interfacing c++ and prolog

**URL:** <https://swi-prolog.discourse.group/t/list-manipulation-when-interfacing-c-and-prolog/2610>\
**Category:** Help!\
**Created:** [July 7, 2020, 12:01pm UTC](https://swi-prolog.discourse.group/t/list-manipulation-when-interfacing-c-and-prolog/2610 "2020-07-07T12:01:28Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![koefan](https://avatars.discourse-cdn.com/v4/letter/k/dfb087/32.png) [@koefan](https://swi-prolog.discourse.group/u/koefan)\
**Post date:** [July 7, 2020, 12:01pm UTC](https://swi-prolog.discourse.group/t/list-manipulation-when-interfacing-c-and-prolog/2610/1 "2020-07-07T12:01:28Z")

</div>

I am having some issues with manipulating lists when interfacing C++ and Swi-Prolog. I’m using: SWI-Prolog version 8.2.0.

I have a Prolog file containing the single fact:

```prolog
test([foo,bar]).

```

and I have the following c++ function for building a list:

```prolog
int main(int argc, char **argv)
{
    PlEngine e(argv[0]);
    PlTermv av(1);
    PlTail my_list(av[0]);
    my_list.append("foo");
    my_list.append("bar");
    my_list.close();
    
    if ( PlCall("test", my_list) )
      cout << 1;
    else
        cout << 0;
    
    exit(1);
}

```

At this stage, I want to check the list I am building is [foo,bar]. However, running this script returns 0 - I am compiling and executing both the cpp and pl file. Could you please advice on how to build and manipulate lists? Am I missing something about how the append function and PlTail class behave?

Thanks!

---

<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:** [July 7, 2020, 2:33pm UTC](https://swi-prolog.discourse.group/t/list-manipulation-when-interfacing-c-and-prolog/2610/2 "2020-07-07T14:33:09Z")

</div>

This is cross-posted at [StackOverflow](https://stackoverflow.com/q/62765831/1243762).
