Rebol3 Code Examplex
Old lady swallowed a fly
Present a program which emits the lyrics to the song "I Knew an Old Lady Who Swallowed a Fly", taking advantage of the repetitive structure of the song's lyrics.
Rebol [
title: "Rosetta code: Old lady swallowed a fly"
file: %Old_lady_swallowed_a_fly.r3
url: https://rosettacode.org/wiki/Old_lady_swallowed_a_fly
]
animals: [
fly spider bird cat dog goat cow horse
]
verses: [
"I don't know why she swallowed that fly.^/Perhaps she'll die"
"That wiggled and jiggled and tickled inside her"
"How absurd, to swallow a bird"
"Imagine that. She swallowed a cat"
"What a hog to swallow a dog"
"She just opened her throat and swallowed that goat"
"I don't know how she swallowed that cow"
"She's dead of course"
]
repeat i length? animals [
print ["There was an old lady who swallowed a" animals/:i]
print verses/:i
if i < length? animals [
for j i 2 -1 [
print ["She swallowed the" animals/:j "to catch the" animals/(j - 1)]
if j = 2 [print verses/1]
]
]
print ""
]
Output:
There was an old lady who swallowed a fly
I don't know why she swallowed that fly.
Perhaps she'll die
There was an old lady who swallowed a spider
That wiggled and jiggled and tickled inside her
She swallowed the spider to catch the fly
I don't know why she swallowed that fly.
Perhaps she'll die
There was an old lady who swallowed a bird
How absurd, to swallow a bird
She swallowed the bird to catch the spider
She swallowed the spider to catch the fly
I don't know why she swallowed that fly.
Perhaps she'll die
There was an old lady who swallowed a cat
Imagine that. She swallowed a cat
She swallowed the cat to catch the bird
She swallowed the bird to catch the spider
She swallowed the spider to catch the fly
I don't know why she swallowed that fly.
Perhaps she'll die
There was an old lady who swallowed a dog
What a hog to swallow a dog
She swallowed the dog to catch the cat
She swallowed the cat to catch the bird
She swallowed the bird to catch the spider
She swallowed the spider to catch the fly
I don't know why she swallowed that fly.
Perhaps she'll die
There was an old lady who swallowed a goat
She just opened her throat and swallowed that goat
She swallowed the goat to catch the dog
She swallowed the dog to catch the cat
She swallowed the cat to catch the bird
She swallowed the bird to catch the spider
She swallowed the spider to catch the fly
I don't know why she swallowed that fly.
Perhaps she'll die
There was an old lady who swallowed a cow
I don't know how she swallowed that cow
She swallowed the cow to catch the goat
She swallowed the goat to catch the dog
She swallowed the dog to catch the cat
She swallowed the cat to catch the bird
She swallowed the bird to catch the spider
She swallowed the spider to catch the fly
I don't know why she swallowed that fly.
Perhaps she'll die
There was an old lady who swallowed a horse
She's dead of course