home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume10 / ifp / part01 / fproot / demo / PigLatin < prev    next >
Encoding:
Text File  |  1987-07-05  |  935 b   |  46 lines

  1. (*
  2.  * Convert sequence of words to pig-latin
  3.  *
  4.  * E.g.
  5.  *      <Have a nice day> : PigLatin -> <aveHay a icenay ayday>
  6.  *
  7.  * The text processing is done via explode and implode.
  8.  * `explode' converts a string into a sequence of characters (1 letter strings),
  9.  * `implode' catenates a sequence of strings into a single string.
  10.  *
  11.  * Coded by Kevin Kenny and Arch Robison
  12.  *)
  13.  
  14. DEF PigLatin AS
  15.  
  16.    EACH
  17.       explode |
  18.  
  19.       IF EACH Vowel END | any | ~ THEN id    (* Not a word, don't mangle it *)
  20.       ELSE
  21.  
  22.          IF 1|Vowel|~ THEN
  23.  
  24.             (* Word begins with a consonant - rotate first vowel to front. *)
  25.  
  26.             WHILE 1|Vowel|~ DO
  27.                [tl,1]|apndr
  28.             END
  29.  
  30.          ELSIF [1r|Vowel, [#<y Y>,1r]|member] | or THEN
  31.  
  32.             (* Word ends in vowel or 'y' - append a 'w' *)
  33.  
  34.             [id,#w] | apndr
  35.  
  36.          ELSE id
  37.          END |
  38.  
  39.          [id,#<a y>] | cat
  40.  
  41.       END |
  42.  
  43.       implode
  44.    END;
  45.  
  46.