921kiyo
921kiyo

Reputation: 572

How to use list constructors (./2) in SWI-Prolog

I am trying to use list constructor in SWI-Prolog, but am getting 'dict' expected error.

For example,

.(a, []) == [a].

ERROR: Type error: `dict' expected, found `a' (an atom)
ERROR: In:
ERROR:   [11] throw(error(type_error(dict,a),_14808))
ERROR:   [10] '$type_error'(dict,a) at /Applications/SWI-Prolog.app/Contents/swipl/boot/init.pl:3369
ERROR:    [9] '$dicts':'.'(a,[],_14874) at /Applications/SWI-Prolog.app/Contents/swipl/boot/dicts.pl:46
ERROR:    [8] '<meta-call>'(user:(...,...)) <foreign>
ERROR:    [7] <user>
Exception: (9) '.'(a, [], _14200) ? 

Could anyone help me configure this functionality?

Upvotes: 4

Views: 652

Answers (2)

Armatorix
Armatorix

Reputation: 1128

Better to use | in conventional notation,

?- X = '[|]'(1,[0]).
X = [1, 0].

can be write like this

?- X = [1|[0]].
X = [1, 0].

Upvotes: 2

Paulo Moura
Paulo Moura

Reputation: 18683

SWI-Prolog 7.x uses a different list constructor, '[|]'/2, instead of the traditional ./2 Prolog constructor:

?- '[|]'(1,[]) == [1].
true.

The change was motivated to free ./2 for other uses, notably in dict terms, as hinted in the error message you got for your query.

Upvotes: 5

Related Questions