我有一个 Z 规范,我必须将它翻译成 Prolog 代码。我尝试但它不起作用所以有人可以帮助我吗?
linkedListInit(LinkedList) :-
LinkedList = {[linked,L],[size, S]} &
list(L) &
S is 0.
insert(LinkedList,Node_i,LinkedList_):-
insertNode(LinkedList,Node_i,LinkedList_).
insertNode(LinkedList,Node_i,LinkedList_):-
LinkedList = {[linked,L],[size,S]} &
concat(L,Node_i,L_) &
S_ is S + 1 &
LinkedList_ = {[linked,L_],[size,S_]}.
extract(LinkedList,Node_i,LinkedList_):-
extractHeadNodeOk(LinkedList,Node_i,Msg_o,LinkedList_)
or
extractHeadNodeError(LinkedList,Node_i,Msg_o,LinkedList_).
extractHeadNodeOk(LinkedList,Node_i,Msg_o,LinkedList_):-
LinkedList = {[linked,L],[size,S]} &
L neq {} &
tail(L,L_) &
head(L,Node_i) &
S_ is S-1 &
Msg_o = ok &
LinkedList_ = {[linked,L_],[size,S_]}.
extractHeadNodeError(LinkedList,Node_i,Msg_o,LinkedList_):-
LinkedList = {[linked,L] / _} &
slits(L) &
L = {} &
(nran(L,D) &
Node_i in D) &
Msg_o = error &
LinkedList_ = LinkedList.
checkNode(LinkedList,Node_i,LinkedList_):-
checkNodeOk(LinkedList,Node_i,Msg_o,LinkedList_)
or
checkNodeError(LinkedList,Node_i,Msg_o,LinkedList_).
checkNodeOk(LinkedList,Node_i,Msg_o,LinkedList_):-
LinkedList = {[linked,L],[size,S]} &
(ran(L,D) &
Node_i in D) &
Msg = ok &
LinkedList_ = LinkedList.
checkNodeError(LinkedList,Node_i,Msg_o,LinkedList_):-
LinkedList = {[linked,L] / _} &
(nran(L,D) &
Node_i in D) &
Msg = error &
LinkedList_ = LinkedList.
removePartialNode(LinkedList,Node_i,LinkedList_):-
removePartialNodeOk(LinkedList,Node_i,Msg_o,LinkedList_)
or
removePartialNodeError(LinkedList,Node_i,Msg_o,LinkedList_).
removePartialNodeOk(LinkedList,Node_i,Msg_o,LinkedList_):-
LinkedList = {[linked,L],[size,S]} &
(ran(L,D) &
Node_i in D) &
dares(dom(filter(L,Node_i,R),A),L,L_) &
Msg_o = ok &
LinkedList_ = {[linked,L_],[size,S_]}.
removePartialNodeError(LinkedList,Node_i,Msg_o,LinkedList_):-
LinkedList = {[linked,L] / _} &
(nran(L,D) &
Node_i in D) &
Msg_o = error &
LinkedList_ = LinkedList.
removePartialData(LinkedList,Node_i,Data_i,LinkedList_):-
removePartialDataOk(LinkedList,Node_i,Data_i,Msg_o,LinkedList_)
or
removePartialDataError(LinkedList,Node_i,Data_i,Msg_o,LinkedList_).
removePartialDataOk(LinkedList,Node_i,Data_i,Msg_o,LinkedList_):-
LinkedList = {[linked,L],[size,S]} &
(ran(L,D) &
Node_i in D) &
(ran(Data_i,F) &
Data_i in F) &
dares(dom(filter(L,rres(Data_i,Node_i,S),A),L,L_) &
Msg_o = ok &
LinkedList_ = {[linked,L_],[size,S_]}.
removePartialDataError(LinkedList,Node_i,Data_i,Msg_o,LinkedList_):-
LinkedList = {[linked,L] / _} &
(ran(L,D) &
Node_i in D) &
(nran(Data_i,F) &
Data_i in F) &
Msg_o = error &
LinkedList_ = LinkedList.