learn-prolog-now-exercises
learn-prolog-now-exercises copied to clipboard
Ex 4.2 #7 is probably correct definition
I tried the following assert([[1,2]|4]). and it returned true. Why is it labelled as syntactically incorrect?
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 :)
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.