Grain of Salt - November 20th, 2010 [entries|archive|friends|userinfo]
snauts

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

November 20th, 2010

[Nov. 20th, 2010|10:31 am]
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.
linkpost comment

navigation
[ viewing | November 20th, 2010 ]
[ go | Previous Day|Next Day ]