home *** CD-ROM | disk | FTP | other *** search
/ Programmer Plus 2007 / Programmer-Plus-2007.iso / Programming / Borland Plateform / Turbo Prolog 2 / EXAMPL56.PRO < prev    next >
Encoding:
Prolog Source  |  1986-04-25  |  1.3 KB  |  50 lines

  1.                       /* Program 56 */
  2. domains
  3.     letter = symbol
  4.     word = letter*
  5. predicates
  6.     divide(word,word,word,word)
  7.     vocal(letter)
  8.     consonant(letter)
  9.     string_word(string,word)
  10.     append(word,word,word)
  11.  
  12. goal
  13.     clearwindow(),
  14.     write("Write a word: "),
  15.     readln(S),
  16.     string_word(S,Word),
  17.     append(First,Second,Word),
  18.     divide(First,Second,Part1,Part2),
  19.     string_word(Syllable1,Part1),
  20.     string_word(Syllable2,Part2),
  21.     write("Division: ",Syllable1,"-",Syllable2),nl,
  22.     fail.
  23. clauses
  24.     divide(Start,[T1,T2,T3|Rest],D1,[T2,T3|Rest]):-
  25.         vocal(T1),consonant(T2),vocal(T3),
  26.         append(Start,[T1],D1).
  27.     divide(Start,[T1,T2,T3,T4|Rest],D1,[T3,T4|Rest]):-
  28.         vocal(T1),consonant(T2),consonant(T3),vocal(T4),
  29.         append(Start,[T1,T2],D1).
  30.     divide(Start,[T1|Rest],D1,D2):-
  31.         append(Start,[T1],S),
  32.         divide(S,Rest,D1,D2).
  33.         
  34.     vocal(a).vocal(e).vocal(i).vocal(o).vocal(u).vocal(y).
  35.  
  36.     consonant(B):-
  37.         not(vocal(B)), B <= z, a <= B.
  38.  
  39.     string_word("",[]):-!.
  40.     string_word(Str,[H|T]):-
  41.         bound(Str),frontstr(1,Str,H,S),string_word(S,T).
  42.     string_word(Str,[H|T]):-
  43.         free(Str),bound(H),string_word(S,T),
  44.         concat(H,S,Str).
  45.  
  46.     append([],L,L):-!.
  47.     append([X|L1],L2,[X|L3]) :- 
  48.         append(L1,L2,L3).
  49.  
  50.