Article
Jean Millette · Oct 26, 2022 6m read

The Name Game: Using a Popular Song as Spec for Introductory ObjectScript/Python Project

TL;DR: This article describes an introductory-level project that exercises some string-manipulation functions in both ObjectScript and Python…with specs from a song.

After you’ve written your first “Hello World!” program, are you ready for a new fun challenge?  An old, very popular (at the time) song may be just what you need.

While I was driving around on vacation in southern Maine, the local “Legends” radio station played the old classic, “The Name Game” by Shirley Ellis (https://www.youtube.com/watch?v=5MJLi5_dyn0). If the listener resists the urge to get up and dance and instead listens closely to the lyrics, he or she will hear very specific instructions on how “The Name Game” works.

Software developers DREAM of having such clear and precise specifications, along with examples of the expected input and output.

The main idea of the “name game” is to convert someone’s name into verses of the song, verses that fans have sung many times over these past 60 years. The song has been covered by many artists; Laura Branigan did a popular version in the 1980s: https://www.youtube.com/watch?v=80vm4z1puT8 It was also used in an episode of the “American Horror Story” TV series. I’ve never seen the episode, but I hope it wasn’t about someone trying to write a program that generates lyrics for a song (the horror!).

The ”Specs”

The full lyrics are found at https://www.lyrics.com/lyric/18378399/Shirley+Ellis/Name+Game , but here are the verses with “the specs”:

The first letter of the name
I treat it like it wasn't there
But a "B" or an "F"
Or an "M" will appear

And then I say "Bo" add a "B" then I say the name
Then "Bo-na-na fanna" and "fo"
And then I say the name again with an ""f" very plain
Then "fee fi" and a "mo"
And then I say the name again with an "M" this time

But if the first two letters are ever the same
I drop them both, then say the name


That's the only rule that is contrary

The Code

The code shown below is a mix of ObjectScript and embedded python and (hopefully) enough comments to be self-explanatory.

Class Sandbox.NameGame Extends (%Persistent, %Populate, %XML.Adaptor)
{

/*
Shirley!
Shirley, Shirley Bo-ber-ley
Bo-na-na fanna Fo-fer-ley
Fee-fi-mo-mer-ley
Shirley!
*/
/// Given a name, generate a verse of "The Name Game" song with that person's name.
ClassMethod GenerateStanza(name1 As %String)
{
    // Remove the first letter (or first consonant blend) and be ready to add “B”, “F”, and “M” to the beginning of what’s left
    // Returns the first letter to later determine if the name fits “the only rule that is contrary”…
    set nameParts = ..StripLeadingConsonants(name1)
    set leadConsonants = nameParts."__getitem__"("consonants")
    set nameRoot = nameParts."__getitem__"("nameRoot")

    // One thing she doesn’t mention is shouting the name...but we know this from examples in song.
    // Let's upper-class it with old-school ObjectScript and add an exclamation point
    set exclaimTheName = $ZCONVERT(name1,"U")_"!"
    w !,exclaimTheName,!

    // And then repeating it twice before the remaining shenanigans
    w ..RepeatName(name1)_" "
    // As she does describe in the rest of the "specifiation"…
    // And then I say "Bo" add a "B" then I say the (modified) name
    w ..AddBoAndB(nameRoot, leadConsonants),!

    // Then "Bo-na-na fanna" and "fo"
    // add a "F" then I say the (modified) name
    w ..AddBonanaFanaFoF(nameRoot, leadConsonants),!

    // Then "fee fi" and a "mo"
    // add a "F" then I say the (modified) name
    w ..AddFeeFiMoM(nameRoot, leadConsonants),!

    // Exclaim the name again!
    w exclaimTheName,!!
}

ClassMethod RepeatName(name1 As %String) As %String [ Language = python ]
{
    line = name1+", "+name1
    return(line)
}

/// Parse the name into its initial consonants and the rest as the root of the name
ClassMethod StripLeadingConsonants(name As %String) As %String [ Language = python ]
{
    # Find the first vowel
    vowelIndex = -1
    for i in range(len(name)):
        if name[i] in "aeiouAEIOU":
            vowelIndex = i
            break
    # copy the string from the first vowel to the end and return that
    strippedString = name[vowelIndex:len(name)]

    # copy the initial consonant(s) into another string
    consonants = name[0:vowelIndex]

    # Return two values as a "tuple"...but couldn't figure out syntax on the ObjectStript side to access each element. 
    # Exercise for the reader
    #return consonants, strippedString

    # Return a dict is wordier, but more descriptive for the caller
    returnDict = {
        "consonants" : consonants,
        "nameRoot" : strippedString
    }
    return returnDict
}

// Bo-ber-ley
ClassMethod AddBoAndB(nameRoot As %String, leadConsonants As %String) As %String [ Language = python ]
{
    firstLetter1 = leadConsonants
    firstLetter2 = "b"
    # Apply "the only rule that is contrary"
    # But if the first two letters are ever the same
    # drop them both, then say the name
    if (firstLetter1.lower()[0] == firstLetter2):
        # Like Bob, Bob, drop the "B's", Bo-ob   
        firstLetter2 = ""
    line = "Bo-"+firstLetter2+nameRoot
    return line
}

// Bo-na-na fanna Fo-fer-ley
ClassMethod AddBonanaFanaFoF(nameRoot As %String, leadConsonants As %String) As %String [ Language = python ]
{
    firstLetter1 = leadConsonants
    firstLetter2 = "f"
    # Apply "the only rule that is contrary" (see above)
    # But if the first two letters are ever the same
    # drop them both, then say the name
    if (firstLetter1.lower()[0] == firstLetter2):
        # Or Fred, Fred, drop the "F's", Fo-red   
        firstLetter2 = ""
    line = "Bo-na-na fanna Fo-"+firstLetter2+nameRoot
    return(line)
}

// Fee-fi-mo-mer-ley
ClassMethod AddFeeFiMoM(nameRoot As %String, leadConsonants As %String) As %String [ Language = python ]
{
    firstLetter1 = leadConsonants
    firstLetter2 = "m"
    # Apply "the only rule that is contrary" (see above)
    # But if the first two letters are ever the same
    # drop them both, then say the name
    if (firstLetter1.lower()[0] == firstLetter2):
        # Or Mary, Mary, drop the "M's", Mo-ary  
        firstLetter2 = ""
    line = "Fee-fi-mo-"+firstLetter2+nameRoot
    return(line)
}

ClassMethod GenerateStanzaPy(name1 As %String) [ Language = python ]
{
    #v One thing she doesn’t mention is repeating the name twice before the remaining shenanigans
    import iris
    print(name1.upper()+"!")
    repeated = iris.cls(__name__).RepeatName(name1)
    print(repeated)
    print("name=<"+__name__+">")

    # All-python solution left to the reader
    # But she does mention the rest…
    # Remove the first letter (or first consonant blend) and be ready to add “B”, “F”, and “M” to the beginning of what’s left
    # Determine if the name fits “the only rule that is contrary”…

    # And then I say "Bo" add a "B" then I say the (modified) name
    # Then "Bo-na-na fanna" and "fo"
    # add a "F" then I say the (modified) name
    # Then "fee fi" and a "mo"
    # add a "F" then I say the (modified) name
}

}

Please feel free to steal, expand, and/or comment. Comments in the code point to some “exercises for the reader”, one of which is for something I couldn’t figure out.

Note: Amazon has already developed a “Name Game” app that can be played with Alexa (Tell Alexa your name and she’ll sing a verse with that name). Somewhere in the guts of their software is code that uses similar logic as above. The same can be said for a couple of web pages, one of which is linked here: https://thenamegame-generator.com/

Other ideas and more information:

This “Name Game” describes how to sing verses of the song. I searched for dance songs that might have “specs” describing how to do a dance described in the song (think “The Hokey-Pokey”, but more fun). Such a song could be used to program a robot to do at least part of that dance. The closest I could find is “The Loco-Motion” https://www.youtube.com/watch?v=IY-63KHQSdc, which directs the listener (robot?) to “swing your hips, jump up, jump back”, but not much else. Any others out there?

Finally, for more information, there are good “python/ObjectScript” code sample articles within the developer community, including the following:

InterSystems IRIS 2021.2+ Python Examples (Embedded, Native APIs and

Python and IRIS in practice - with examples! | InterSystems Developer

FUN>do ##class(Sandbox.NameGame).GenerateStanza("Foster")
 
FOSTER!
Foster, Foster Bo-boster
Bo-na-na fanna Fo-oster
Fee-fi-mo-moster
FOSTER!
 
 
FUN>do ##class(Sandbox.NameGame).GenerateStanza("Marvin")
 
MARVIN!
Marvin, Marvin Bo-barvin
Bo-na-na fanna Fo-farvin
Fee-fi-mo-arvin
MARVIN!
8
0 177
Discussion (3)2
Log in or sign up to continue

@Jean Millette  - I love it!  Thank you for this fun contribution to the Developer Community :)

Thanks @Ben Spead! It was fun to do and hope it helps (in a small way) increase people's use/understanding of embedded python. 

If you're looking for a song with instructions you could try  Cha Cha Slide by DJ Casper.  Although I can't help you on how to do the charlie brown. 
https://g.co/kgs/JdWTca

[...]
Everybody clap your handsClap, clap, clap, clap your handsClap, clap, clap, clap your handsAlright now, we're going to do the basic step

To the leftTake it back now, y'allOne hop this timeRight foot, let's stompLeft foot, let's stompCha cha real smooth
[...]