dragonwasrobot / learn-prolog-now-exercises

My solutions to the exercises and practical sessions of the book 'Learn Prolog Now!' by Patrick Blackburn, Johan Bos, and Kristina Striegnitz.
288 stars 81 forks source link

Ex 4.2 #7 is probably correct definition #45

Open BrazilForever11 opened 5 years ago

BrazilForever11 commented 5 years ago

I tried the following assert([[1,2]|4]). and it returned true. Why is it labelled as syntactically incorrect?

dragonwasrobot commented 5 years ago

Hi, its been many years since I've actively written Prolog, so unfortunately can't answer any questions with much confidence, however if you believe that there is an error in my solution feel free to submit a PR that fixes it :)

hailangvn commented 5 years ago

Hi Brazil, I learned to use [filename] to load knowledge file. After I tried assert([[1,2]|4]) statement, I could not load knowledge file any more by that way. I need to quit swipl to clear the effect. So that statement already did wrong thing. IMHO, to test list term, we need to use list predicates. Below is the result of using member/2. Note there is no space before period '.' at the first answer.

?- member(X,[[1,2]|4]).
X = [1, 2].

?- member(X,[[1,2]|[4]]).
X = [1, 2] ;
X = 4.

So the [[1,2]|4] is incorrect as it does not give desired result, which is concatenate two list. I just don't know if the term syntactically is applicable or not. :)

By the way, thanks dragonwasrobot for sharing the solutions.