Grain of Salt - Post a comment [entries|archive|friends|userinfo]
snauts

[ userinfo | sc userinfo ]
[ archive | journal archive ]

Nov. 20th, 2010|10:31 am

snauts
Vispār es nezinu vai tas ir pareizais veids to tā darīt, bet parastā prologā arī var taisīt tādus trikus kādus manīju SICP grāmatā:
  uber(append,[X|Y],Z,[X|W]) :- uber(append,Y,Z,W).
  uber(append,[],X,X).

  uber(reverse,[X|Y],Z) :- uber(reverse,Y,W), uber(append,W,[X],Z).
  uber(reverse,[],[]).

  uber(member,X,[X|R]).
  uber(member,X,[Y|R]) :- uber(member,X,R).

pēc tam var vaicāt šādi:
  ?- uber(X,[a,b],[c,d],[a,b,c,d]).
  X = append ;
  false.

  ?- uber(X, b, [a,b,c]).
  X = member ;
  false.

  ?- uber(X, [a,b,c], [c,b,a]).
  X = reverse ;
  false.
link Read Comments

Reply:
From:
Username:
Password:
Ievadi te 'qws' (liidzeklis pret spambotiem):
Subject:
No HTML allowed in subject
  
Message:

Notice! This user has turned on the option that logs IP addresses of anonymous posters.