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

后端 未结 2 545
执念已碎
执念已碎 2020-12-20 23:17

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

For example,

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

ERROR: Type error: `dict\         


        
相关标签:
2条回答
  • 2020-12-20 23:49

    Better to use | in conventional notation,

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

    can be write like this

    ?- X = [1|[0]].
    X = [1, 0].
    
    0 讨论(0)
  • 2020-12-21 00:11

    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.

    0 讨论(0)
提交回复
热议问题