Article View: comp.lang.prolog
Article #1632Re: simple list processing predicates
From: Lee Naish
Date: Thu, 15 Oct 1992 07:34
Date: Thu, 15 Oct 1992 07:34
32 lines
1421 bytes
1421 bytes
In article <9210122012.AA08759@enuxha.eas.asu.edu> gomez@enuxha.eas.asu.edu (JL Gomez) writes: >I've been learning PROLOG and building up some list predicates. > >One of them is a subsequence predicate which returns yes if the elements >in the first list match the elements in the second list. > >The others are rotate predicates like: > >rotate([a,b,c,d,e],2,X). >X = [c,d,e,a,b] > >which rotates right, and then > >rotate([a,b,c,d,e,f],-2,X] >X = [e,f,a,b,c,d] % true if Sub is a "subsequence" (not necessarily contiguous) % of Seq subseq([], _). subseq(A.Sub, A.Seq) :- subseq(Sub, Seq). subseq(Sub, _.Seq) :- subseq(Sub, Seq). % rotates list to right or left (shift can be negative) rotate(List, Shift, RotatedList) :- length(List, Len), LenH is (Shift + Len) mod Len, length(H, LenH), append(H, T, List), append(T, H, RotatedList).
Technical Details
Message-ID:
<9228917.11974@mulga.cs.mu.OZ.AU>Path:
arc1-ca.pugleaf.net!sparky!uunet!charon.amdahl.com!pacbell.com!iggy.GW.Vitalink.COM!cs.widener.edu!eff!sol.ctr.columbia.edu!caen!batcomputer!munnari.oz.au!cs.mu.OZ.AU!munta.cs.mu.OZ.AU!leeReferences:
<9210122012.AA08759@enuxha.eas.asu.edu>Show Full Headers
Complete Article Headers
Newsgroups: comp.lang.prolog Path: arc1-ca.pugleaf.net!sparky!uunet!charon.amdahl.com!pacbell.com!iggy.GW.Vitalink.COM!cs.widener.edu!eff!sol.ctr.columbia.edu!caen!batcomputer!munnari.oz.au!cs.mu.OZ.AU!munta.cs.mu.OZ.AU!lee From: lee@munta.cs.mu.OZ.AU (Lee Naish) Subject: Re: simple list processing predicates Message-ID: <9228917.11974@mulga.cs.mu.OZ.AU> Sender: news@cs.mu.OZ.AU Organization: Department of Computer Sci, University of Melbourne References: <9210122012.AA08759@enuxha.eas.asu.edu> Date: Thu, 15 Oct 1992 07:34:33 GMT Lines: 32