home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 9 / 09.iso / l / l217 / 2.ddi / EXAMPLES / CH13EX03.PRO < prev    next >
Encoding:
Prolog Source  |  1990-03-26  |  634 b   |  27 lines

  1. /*
  2.    Copyright (c) 1986, 90 by Prolog Development Center
  3. */
  4. predicates
  5. nondeterm nd_searchchar(string,char,integer)
  6. nondeterm nd_searchchar1(string,char,integer,integer)
  7. nondeterm nd_sc(string,char,integer,integer,integer)
  8.  
  9. clauses
  10. nd_searchchar(Str,Ch,Pos):-
  11.     nd_searchchar1(Str,Ch,Pos,0).
  12.  
  13. nd_searchchar1(Str,Ch,Pos,Old):-
  14.     searchchar(Str,Ch,Pos1),
  15.     nd_sc(Str,Ch,Pos,Pos1,Old).
  16.  
  17. nd_sc(_,_,Pos,Pos1,Old):- Pos = Pos1+Old.
  18. nd_sc(Str,Ch,Pos,Pos1,Old):-
  19.     frontstr(Pos1,Str,_,Rest),
  20.     Old1 = Old + Pos1,
  21.     nd_searchchar1(Rest,Ch,Pos,Old1).
  22.  
  23. goal
  24.     nd_searchchar("abbalblablabbala",'a',P),
  25.     write(P,'\n'),
  26.     fail.
  27.