What (exactly) is {}?

newbie question. I’ve seen it in some clp libs.

It’s an atom, see here

?- {} =.. L.
L = [{}].

?- atom({}).
true.

?- {a, b} =.. L.
L = [{},  (a, b)].

?- {a, b} = {}(a, b).
false.

?- {a, b} = {}((a, b)).
true.

It is used in several places, for example, in DCGs, when representing of foreign languages. In clp, you put constraints into {}/1.

1 Like

Can you give an example of code where it is used?


If you are referring to this usage in fd_dom/2

dom_integers(D, Is) :- phrase(dom_integers_(D), Is).

dom_integers_(I)      --> { integer(I) }, [I].
dom_integers_(L..U)   --> { numlist(L, U, Is) }, Is.
dom_integers_(D1\/D2) --> dom_integers_(D1), dom_integers_(D2).

then notice the --> which identifies DCG. Also see dcg_translate_rule/2

The {...} are part of DCGs which notes

Code between {} is interpreted as plain Prolog code

See also block operators: SWI-Prolog -- Manual

For example of clp usage see: SWI-Prolog -- Manual

1 Like