# List\_to\_fdset/2

**URL:** <https://swi-prolog.discourse.group/t/list-to-fdset-2/5914>\
**Category:** Help!\
**Tags:** swish, clpfd\
**Created:** [November 6, 2022, 10:14pm UTC](https://swi-prolog.discourse.group/t/list-to-fdset-2/5914 "2022-11-06T22:14:14Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![albangabillon](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/albangabillon/32/3689_2.png) [@albangabillon](https://swi-prolog.discourse.group/u/albangabillon)\
**Post date:** [November 6, 2022, 10:14pm UTC](https://swi-prolog.discourse.group/t/list-to-fdset-2/5914/1 "2022-11-06T22:14:14Z")

</div>

Hi,

I wanted to naively translate a list of integers into a finite domain set but I got this error which I am unable to interpret.

```prolog
L = [1,3,5], list_to_fdset(L, S), X in S.
Domain error: `clpfd_domain' expected, found `split(2,from_to(n(1),n(1)),split(4,from_to(n(3),n(3)),from_to(n(5),n(5))))'
In:
   [4] throw(error(domain_error(clpfd_domain,...),_1868))
   [2] clpfd:drep_to_domain(split(2,from_to(...,...),split(4,...,...)),_1922) at /usr/lib/swipl/library/clp/clpfd.pl:3704
   [1] clpfd:clpfd_in(_1988,split(2,from_to(...,...),split(4,...,...))) at /usr/lib/swipl/library/clp/clpfd.pl:1657

```

---

<div class="post-metadata">

**Author:** ![swi](https://avatars.discourse-cdn.com/v4/letter/s/51bf81/32.png) [@swi](https://swi-prolog.discourse.group/u/swi)\
**Post date:** [November 6, 2022, 10:55pm UTC](https://swi-prolog.discourse.group/t/list-to-fdset-2/5914/2 "2022-11-06T22:55:39Z")

</div>

> [@albangabillon](#):
>
> `L = [1,3,5], list_to_fdset(L, S)`

An `fdset` is not the same as a `domain` (it is the internal representation of a domain). The `in` operator works on domains.

If you want to use the `fdset` directly you can use `in_set` instead:

```prolog

16 ?- L = [1,3,5], list_to_fdset(L, FD), X in_set FD.
L = [1, 3, 5],
FD = split(2, from_to(n(1), n(1)), split(4, from_to(n(3), n(3)), from_to(n(5), n(5)))),
X in 1\/3\/5.

```

If you want to use `in` you have to convert the `fdset` to a domain using fdset\_to\_range/2:

```prolog
17 ?- L = [1,3,5], list_to_fdset(L, FD), 
      fdset_to_range(FD,Domain), 
      X in Domain.
L = [1, 3, 5],
FD = split(2, from_to(n(1), n(1)), split(4, from_to(n(3), n(3)), from_to(n(5), n(5)))),
Domain = 1\/3\/5,
X in 1\/3\/5.

```

Note the warning in the [clpfd docs](https://www.swi-prolog.org/pldoc/man?section=clpfd):

> Note that the exact term representation of FD sets is unspecified and will vary across CLP(FD)  
> implementations or even different versions of the same implementation. FD set terms should be  
> manipulated only using the predicates in this section. The behavior of other operations on FD  
> set terms is undefined. In particular, you should not construct or deconstruct FD sets by  
> unification, and you cannot reliably compare FD sets using unification or generic term  
> equality/comparison predicates.

---

<div class="post-metadata">

**Author:** ![albangabillon](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/albangabillon/32/3689_2.png) [@albangabillon](https://swi-prolog.discourse.group/u/albangabillon)\
**Post date:** [November 6, 2022, 11:17pm UTC](https://swi-prolog.discourse.group/t/list-to-fdset-2/5914/3 "2022-11-06T23:17:53Z")

</div>

I didn’t know the difference between fdsets and domains. I got it: fdset are internal representation of domains.  
Thank you
