Rebol3 Code Examplex


The Name Game

Implement the classic Shirley Ellis rhyme pattern that transforms any name into a playful, rule-based chant.

Rebol [
    title: "Rosetta code: The Name Game"
    file:  %The_Name_Game.r3
    url:   https://rosettacode.org/wiki/The_Name_Game
]

verse: function [
    "Print one verse of The Name Game for a given name"
    x [string!]
][
    x1: first x                     ;; first letter
    y:  next x                      ;; rest of the name
    if find "AEIOU" x1 [
        y: ajoin [lowercase x1 y]   ;; keep vowel start, lowercased
    ]
    b: ajoin [#"b" y]
    f: ajoin [#"f" y]
    m: ajoin [#"m" y]
    case [
        x1 == #"B" [b: y]           ;; avoid doubled B-sound
        x1 == #"F" [f: y]           ;; avoid doubled F-sound
        x1 == #"M" [m: y]           ;; avoid doubled M-sound
    ]
    print ajoin [x ", " x ", bo-" b]
    print ajoin ["Banana-fana fo-" f]
    print ajoin ["Fee-fi-mo-" m]
    print ajoin [x "!" LF]
]

foreach n ["Gary" "Earl" "Billy" "Felix" "Mary"] [ verse n ]

Output:

Gary, Gary, bo-bary
Banana-fana fo-fary
Fee-fi-mo-mary
Gary!

Earl, Earl, bo-bearl
Banana-fana fo-fearl
Fee-fi-mo-mearl
Earl!

Billy, Billy, bo-illy
Banana-fana fo-filly
Fee-fi-mo-milly
Billy!

Felix, Felix, bo-belix
Banana-fana fo-elix
Fee-fi-mo-melix
Felix!

Mary, Mary, bo-bary
Banana-fana fo-fary
Fee-fi-mo-ary
Mary!