package house // ASong holds the data we need to generate a song type ASong struct { start string clauses []string end string } // Embed takes two strings and returns a string with the embedded func Embed(l, p string) string { return l + " " + p } // Verse takes three things and returns a verse func Verse(start string, clause []string, end string) string { ret := start + " " for i := 0; i < len(clause); i++ { ret += clause[i] + " " } ret += end return ret } // Song generates the whole song func Song() string { jackSong := ASong{ start: "This is", clauses: []string{ "the horse and the hound and the horn\nthat belonged to", "the farmer sowing his corn\nthat kept", "the rooster that crowed in the morn\nthat woke", "the priest all shaven and shorn\nthat married", "the man all tattered and torn\nthat kissed", "the maiden all forlorn\nthat milked", "the cow with the crumpled horn\nthat tossed", "the dog\nthat worried", "the cat\nthat killed", "the rat\nthat ate", "the malt\nthat lay in", }, end: "the house that Jack built.", } var ret string for i := len(jackSong.clauses); i >= 0; i-- { ret += Verse(jackSong.start, jackSong.clauses[i:], jackSong.end) + "\n\n" } // Trim the trailing "\n\n" return ret[:len(ret)-2] }