Шаблон, соответствующий некоторым спискам - разные случаи - PullRequest
0 голосов
/ 25 июня 2018

Различные случаи со списками. Если эти случаи (a) до (h) работают или нет. Если работа, то должны быть приведены результаты. То, что я сделал, было

(a) ?- [s,u,b,s,t,i,t,u,t,e]=[H1,H2|T].
My answer  is H1=[s] ,H2=[u,b,s,t,i,t,u,t], T=[e]
(b)?- [substitute]=[H1|T].
My answer is wrong it cant be done
(c) ?- [[substitute]]=[H1|T].
My answer is H1=[substitute] T=[]
(d)?- [[s,u,b,s],[t,i,t,u,t,e]=[H1|T].
My answer is H1=[s,u,b,s] and T=[t,i,t,u,t,e]
(e)?- [[s,u,b,s], t,i,t,u,t,e]=[H1|T].
My answer is wrong the tail has issues
(f) ?- [[s,u,b,s],[t,i,t,u,t,e]]=[H1,H2|T].
My answer is H1=[s,u,b,s] H2=[t,i,t,u,t,e] T=[]
(g) ?- [[s,u,b,s],[t,i,t,u,t,e]]=[[H1,H2],H3|T].
My answer is wrong
(e)?- f1(a,Y,,f(Z,2))=f1[a,[1,2],f(1,Y)).
first time i see something like this i don't know
(h)?- f2(A,B,C)=f2(a,[1,2,f(1,Y)]).
same as here

1 Ответ

0 голосов
/ 17 июля 2018

Унификация - это сопоставление соответствующих частей терминов.

(a) ?- [ s , u ,   b,s,t,i,t,u,t,e  ] =
       [ s , u  | [b,s,t,i,t,u,t,e] ] =
       [ H1, H2 | T                 ] 

(b) ?- [ substitute      ] =
       [ substitute | [] ] =
       [ H1         | T  ] 

(c) ?- [ [substitute]      ] =
       [ [substitute] | [] ] =
       [ H1           | T  ]

(d) ?- [ [s,u,b,s] ,   [t,i,t,u,t,e]   ] =
       [ [s,u,b,s] | [ [t,i,t,u,t,e] ] ] =
       [ H1        | T                 ]

(e) ?- [ [s,u,b,s] ,  t,i,t,u,t,e  ] =
       [ [s,u,b,s] | [t,i,t,u,t,e] ] =
       [ H1        | T             ]

(f) ?- [ [s,u,b,s] , [t,i,t,u,t,e]      ] =
       [ [s,u,b,s] , [t,i,t,u,t,e] | [] ] =
       [ H1        , H2            | T  ]

(g) ?- [ [s , u , b, s ], [t,i,t,u,t,e]      ] =
       [ [s , u , b, s ], [t,i,t,u,t,e] | [] ] =
       [ [H1,H2 ]       , H3            | T  ]       % fails!

(e) ?- f1( a, Y    , f(Z, 2)) =
       f1( a, [1,2], f(1, Y)) 

(h) ?- f2( A, B            , C) =
       f2( a, [1,2,f(1,Y)] )                          % fails!
...