# Append/3 isn't deterministic if first arg is var?

**URL:** https://swi-prolog.discourse.group/t/append-3-isnt-deterministic-if-first-arg-is-var/969
**Category:** Help!
**Created:** [July 17, 2019, 10:37pm UTC](https://swi-prolog.discourse.group/t/append-3-isnt-deterministic-if-first-arg-is-var/969 "2019-07-17T22:37:52Z")
**Posts on this page:** 1
**Showing post:** 8

<div class="post-metadata">

### Author: ![brebs](https://avatars.discourse-cdn.com/v4/letter/b/e9c0ed/32.png) [@brebs](https://swi-prolog.discourse.group/u/brebs)
#### Post date: [November 8, 2022, 8:13am UTC](https://swi-prolog.discourse.group/t/append-3-isnt-deterministic-if-first-arg-is-var/969/8 "2022-11-08T08:13:27Z")

</div>

As I understand it, the only slight inelegance with swi-prolog’s append/3 currently is the unwanted choicepoint when args 2 & 3 are lists, and arg 1 is var. This solves that issue, with a reasonable performance hit:

```prolog
append2a(Start, End, Both) :-
    % Guard against unwanted choicepoint
    is_list(Both),
    is_list(End),
    !,
    append(Start, End, Both),
    !.
append2a(Start, End, Both) :-
    append(Start, End, Both).

```

I don’t see a need to check the first arg.

Edit: Tweaked to check `Both` then `End` vars, which seems like a slightly more sensible order, for performance/likelihood.

This is basically what jan already wrote above. I don’t see a better way.

---

_[View the full topic](https://swi-prolog.discourse.group/t/append-3-isnt-deterministic-if-first-arg-is-var/969)._
