Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 816
921kiyo Avatar asked Mar 09 '23 22:03

921kiyo


2 Answers

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.

like image 104
Paulo Moura Avatar answered Mar 19 '23 21:03

Paulo Moura


Better to use | in conventional notation,

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

can be write like this

?- X = [1|[0]].
X = [1, 0].
like image 34
Armatorix Avatar answered Mar 19 '23 19:03

Armatorix