No language is complete without a function for converting from English to
Pig Latin.
I thus do my part to make REBOL complete by offering my first version of the
'piglatin' function, to wit:
--------------------------------------
use it like so:
>> do %piglatin.r
Script: "English to Pig Latin" (none)
>> help piglatin
USAGE:
PIGLATIN
DESCRIPTION:
English to Pig Latin
PIGLATIN is a function value.
>> piglatin
Enter phrase to be translated? (no punctuation or caps yet)
the only good thing about free advice is that the price is right
hetay onlyyay oodgay hingtay aboutyay reefay eefayray adviceyay
isyay hattay hetay ricepay icepayray isyay ightray
----------------------------------------------------------------
here is the code:
REBOL [
TITLE: "English to Pig Latin"
ITLETAY: "Englishyay otay Igpay atinlay"
AUTHORYAY: "Ralph Roberts"
ATEDAY: 23-June-2000
]
piglatin: func ["English to Pig Latin"][
vowels: ["a" "e" "i" "o" "u"]
consonants: ["b" "c" "d" "f" "g" "h" "k" "j" "l" "m" "n"
"p" "q" "r" "s" "t" "v" "w" "x" "y" "z"
]
print "Enter phrase to be translated? (no punctuation or caps yet) "
phrase: input
a: parse phrase " "
foreach word a [
switch: 0
atinlay: word
foreach vowel vowels [
vowel: to-char vowel
if vowel = first atinlay [
insert tail atinlay "yay"
prin [atinlay " "]
switch: 1
]
prin ""
]
foreach consonant consonants [
consonant: to-char consonant
if consonant = first atinlay [
b: first atinlay
insert tail atinlay b
insert tail atinlay "ay"
remove head atinlay first atinlay
if switch <> 1 [prin [atinlay " "]
]
]
prin ""
]
]
print ""
]
--------------------------------------------------------------------------
Enjoyyay,
--Ralph Roberts