home *** CD-ROM | disk | FTP | other *** search
Prolog Source | 1990-03-26 | 634 b | 27 lines |
- /*
- Copyright (c) 1986, 90 by Prolog Development Center
- */
- predicates
- nondeterm nd_searchchar(string,char,integer)
- nondeterm nd_searchchar1(string,char,integer,integer)
- nondeterm nd_sc(string,char,integer,integer,integer)
-
- clauses
- nd_searchchar(Str,Ch,Pos):-
- nd_searchchar1(Str,Ch,Pos,0).
-
- nd_searchchar1(Str,Ch,Pos,Old):-
- searchchar(Str,Ch,Pos1),
- nd_sc(Str,Ch,Pos,Pos1,Old).
-
- nd_sc(_,_,Pos,Pos1,Old):- Pos = Pos1+Old.
- nd_sc(Str,Ch,Pos,Pos1,Old):-
- frontstr(Pos1,Str,_,Rest),
- Old1 = Old + Pos1,
- nd_searchchar1(Rest,Ch,Pos,Old1).
-
- goal
- nd_searchchar("abbalblablabbala",'a',P),
- write(P,'\n'),
- fail.