Old lady swallowed a fly: Difference between revisions

Content added Content deleted
No edit summary
mNo edit summary
Line 1,805: Line 1,805:


=={{header|FutureBasic}}==
=={{header|FutureBasic}}==
An added feature of this code is the addition of a proper English voice reciting the rhyme back to you. This is compilable as a standalone app on M1, M2 or Intel Macs.
<syntaxhighlight lang="futurebasic">
<syntaxhighlight lang="futurebasic">
include "NSLog.incl"
include "NSLog.incl"


begin enum output
void local fn OldLadySwallowedAFly
_firstAnimal = 0
NSUInteger i, j, count
_lastAnimal = 7
end enum

local fn OldLadySwallowedAFly
NSUInteger i, j, numberOfAnimals
CFMutableStringRef mutStr = fn MutableStringWithCapacity( 0 )
NSLogClear
CFArrayRef animals = @[@"fly", @"spider", @"bird", @"cat", @"dog", @"goat", @"cow", @"horse"]
CFArrayRef animals = @[@"fly", @"spider", @"bird", @"cat", @"dog", @"goat", @"cow", @"horse.."]
CFArrayRef verses = @[@"",¬
CFArrayRef verses = @[@"",¬
@"I don't know why she swallowed the fly.\nPerhaps she'll die!\n",¬
@"I don't know why she swallowed the fly — perhaps she'll die!\n",¬
@"That wriggled and jiggled and tickled inside her.",¬
@"That wriggled and jiggled and tickled inside her.",¬
@"How absurd, to swallow a bird!",¬
@"How absurd, to swallow a bird!",¬
Line 1,820: Line 1,829:
@"She just opened her throat and swallowed that goat!",¬
@"She just opened her throat and swallowed that goat!",¬
@"I wonder how she swallowed a cow?",¬
@"I wonder how she swallowed a cow?",¬
@"She's dead of course!"]
@"She's dead, of course!"]
count = fn ArrayCount( animals )
numberOfAnimals = len(animals)
for i = 0 to count - 1
for i = 0 to numberOfAnimals -1
NSLog( @"There was an old lady who swallowed a %@.", animals[i] )
NSLog( @"There was an old lady who swallowed a %@.", animals[i] ) : MutableStringAppendFormat( mutStr, @"There was an old lady who swallowed a %@.\n", animals[i] )
if i == 0 then NSLog( @"%@", verses[1] ) : continue
if i == _firstAnimal then NSLog( @"%@", verses[1] ) : MutableStringAppendFormat( mutStr, @"%@\n", verses[1] ) : continue
if i > 0 then NSLog( @"%@", verses[i+1] )
if i > _firstAnimal then NSLog( @"%@", verses[i+1] ) : MutableStringAppendFormat( mutStr, @"%@\n", verses[i+1] )
if i == 7 then exit fn
if i == _lastAnimal then break
if ( i > 0 )
if ( i > 0 )
for j = i to 1 step -1
for j = i to 1 step -1
CFStringRef p
NSLog( @"\tShe swallowed the %@ to catch the %@.", animals[j], animals[j-1] )
if ( j == 1 ) then NSLog( @"%@", verses[1] ) : exit for
if fn StringIsEqual( animals[j-1], @"fly" ) then p = @"." else p = @","
NSLog( @"\tShe swallowed the %@ to catch the %@%@", animals[j], animals[j-1], p ) : MutableStringAppendFormat( mutStr, @"\tShe swallowed the %@ to catch the %@%@\n", animals[j], animals[j-1], p )
if j == 2 then NSLog(@"\tThat wriggled and jiggled and tickled inside her.") : MutableStringAppendString( mutStr, @"\tThat wriggled and jiggled and tickled inside her.\n" )
if j == 1 then NSLog( @"%@", verses[1] ) : MutableStringAppendFormat( mutStr, @"%@\n", verses[1] ) : break
next
next
end if
end if
next
next
SpeechSynthesizerRef ref = fn SpeechSynthesizerWithVoice( @"com.apple.speech.synthesis.voice.daniel.premium" )
fn SpeechSynthesizerStartSpeakingString( ref, mutStr )
end fn
end fn


Line 1,842: Line 1,856:
HandleEvents
HandleEvents
</syntaxhighlight>
</syntaxhighlight>
The following is both printed and recited back as audio in a proper English male voice.
{{out}}
{{out}}
<pre>
<pre>
There was an old lady who swallowed a fly.
There was an old lady who swallowed a fly.
I don't know why she swallowed the fly.
I don't know why she swallowed the fly — perhaps she'll die!
Perhaps she'll die!


There was an old lady who swallowed a spider.
There was an old lady who swallowed a spider.
That wriggled and jiggled and tickled inside her.
That wriggled and jiggled and tickled inside her.
She swallowed the spider to catch the fly.
She swallowed the spider to catch the fly.
I don't know why she swallowed the fly.
I don't know why she swallowed the fly — perhaps she'll die!
Perhaps she'll die!


There was an old lady who swallowed a bird.
There was an old lady who swallowed a bird.
How absurd, to swallow a bird!
How absurd, to swallow a bird!
She swallowed the bird to catch the spider.
She swallowed the bird to catch the spider,
That wriggled and jiggled and tickled inside her.
She swallowed the spider to catch the fly.
She swallowed the spider to catch the fly.
I don't know why she swallowed the fly.
I don't know why she swallowed the fly — perhaps she'll die!
Perhaps she'll die!


There was an old lady who swallowed a cat.
There was an old lady who swallowed a cat.
Imagine that, she swallowed a cat!
Imagine that, she swallowed a cat!
She swallowed the cat to catch the bird.
She swallowed the cat to catch the bird,
She swallowed the bird to catch the spider.
She swallowed the bird to catch the spider,
That wriggled and jiggled and tickled inside her.
She swallowed the spider to catch the fly.
She swallowed the spider to catch the fly.
I don't know why she swallowed the fly.
I don't know why she swallowed the fly — perhaps she'll die!
Perhaps she'll die!


There was an old lady who swallowed a dog.
There was an old lady who swallowed a dog.
What a hog to swallow a dog!
What a hog to swallow a dog!
She swallowed the dog to catch the cat.
She swallowed the dog to catch the cat,
She swallowed the cat to catch the bird.
She swallowed the cat to catch the bird,
She swallowed the bird to catch the spider.
She swallowed the bird to catch the spider,
That wriggled and jiggled and tickled inside her.
She swallowed the spider to catch the fly.
She swallowed the spider to catch the fly.
I don't know why she swallowed the fly.
I don't know why she swallowed the fly — perhaps she'll die!
Perhaps she'll die!


There was an old lady who swallowed a goat.
There was an old lady who swallowed a goat.
She just opened her throat and swallowed that goat!
She just opened her throat and swallowed that goat!
She swallowed the goat to catch the dog.
She swallowed the goat to catch the dog,
She swallowed the dog to catch the cat.
She swallowed the dog to catch the cat,
She swallowed the cat to catch the bird.
She swallowed the cat to catch the bird,
She swallowed the bird to catch the spider.
She swallowed the bird to catch the spider,
That wriggled and jiggled and tickled inside her.
She swallowed the spider to catch the fly.
She swallowed the spider to catch the fly.
I don't know why she swallowed the fly.
I don't know why she swallowed the fly — perhaps she'll die!
Perhaps she'll die!


There was an old lady who swallowed a cow.
There was an old lady who swallowed a cow.
I wonder how she swallowed a cow?
I wonder how she swallowed a cow?
She swallowed the cow to catch the goat.
She swallowed the cow to catch the goat,
She swallowed the goat to catch the dog.
She swallowed the goat to catch the dog,
She swallowed the dog to catch the cat.
She swallowed the dog to catch the cat,
She swallowed the cat to catch the bird.
She swallowed the cat to catch the bird,
She swallowed the bird to catch the spider.
She swallowed the bird to catch the spider,
That wriggled and jiggled and tickled inside her.
She swallowed the spider to catch the fly.
She swallowed the spider to catch the fly.
I don't know why she swallowed the fly.
I don't know why she swallowed the fly — perhaps she'll die!
Perhaps she'll die!


There was an old lady who swallowed a horse.
There was an old lady who swallowed a horse...
She's dead of course!
She's dead, of course!
</pre>
</pre>