Old lady swallowed a fly: Difference between revisions

m
m (syntax highlighting fixup automation)
imported>Arakov
 
(13 intermediate revisions by 10 users not shown)
Line 346:
}</syntaxhighlight>
 
=={{header|Applesoft BASIC}}==
<syntaxhighlight lang="gwbasic"> 100 FOR N = 0 TO 7: READ A$(N),E$(N): NEXT N:N = N - 1
110 FOR C = 1 TO N
120 PRINT M$M$"THERE WAS AN OLD LADY WHO SWALLOWED A "A$(C);
130 LET M$ = CHR$ (13)
140 IF C > 1 THEN PRINT M$E$(C);: IF C < N THEN FOR B = C TO 2 STEP - 1: PRINT M$A$(0)A$(B)" TO CATCH THE "A$(B - 1) MID$ (",;",1 + (B = 2),1);: NEXT B
150 IF C < N THEN PRINT M$E$(1)E$(0);
160 NEXT C
170 END
200 DATA" SHE SWALLOWED A "," - PERHAPS SHE'LL DIE!"
210 DATA"FLY","I DON'T KNOW WHY SHE SWALLOWED A FLY"
220 DATA"SPIDER","THAT WRIGGLED AND JIGGLED AND TICKLED INSIDE HER;"
230 DATA"BIRD","HOW ABSURD TO SWALLOW A BIRD."
240 DATA"CAT","FANCY THAT TO SWALLOW A CAT!"
250 DATA"DOG","WHAT A HOG, TO SWALLOW A DOG;"
260 DATA"COW","I DON'T KNOW HOW SHE SWALLOWED A COW,"
270 DATA"HORSE","SHE'S DEAD, OF COURSE!"</syntaxhighlight>
=={{header|ARM Assembly}}==
<syntaxhighlight lang="text">.global _start
Line 1,426 ⟶ 1,443:
for n from 0 upto 7 do verse(n) od
corp</syntaxhighlight>
 
=={{header|EasyLang}}==
{{trans|C}}
<syntaxhighlight>
animals$[] = [ "fly" "spider" "bird" "cat" "dog" "goat" "cow" "horse" ]
verses$[] = [ "I don't know why she swallowed that fly.\nPerhaps she'll die\n" "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" ]
for i to len animals$[]
print "There was an old lady who swallowed a " & animals$[i]
print verses$[i]
if i < len animals$[]
for j = i downto 2
print "She swallowed the " & animals$[j] & " to catch the " & animals$[j - 1]
if j = 2
print verses$[1]
.
.
.
.
</syntaxhighlight>
 
 
=={{header|Elena}}==
ELENA 56.0x :
<syntaxhighlight lang="elena">import extensions;
Line 1,446 ⟶ 1,483:
public program()
{
for(int i := 0,; i < Creatures.Length,; i += 1)
{
console
Line 1,454 ⟶ 1,491:
if(i != 0 && i != Creatures.Length - 1)
{
for(int j := i,; j > 0,; j -= 1)
{
console.printLineFormatted("She swallowed the {0} to catch the {1}",Creatures[j],Creatures[j - 1])
Line 1,784 ⟶ 1,821:
 
main = putStr $ unlines song</syntaxhighlight>
 
 
 
=={{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">
include "NSLog.incl"
 
begin enum output
_firstAnimal = 0
_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 verses = @[@"",¬
@"I don't know why she swallowed the fly — perhaps she'll die!\n",¬
@"That wriggled 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 wonder how she swallowed a cow?",¬
@"She's dead, of course!"]
numberOfAnimals = len(animals)
for i = 0 to numberOfAnimals -1
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 == _firstAnimal then NSLog( @"%@", verses[1] ) : MutableStringAppendFormat( mutStr, @"%@\n", verses[1] ) : continue
if i > _firstAnimal then NSLog( @"%@", verses[i+1] ) : MutableStringAppendFormat( mutStr, @"%@\n", verses[i+1] )
if i == _lastAnimal then break
if ( i > 0 )
for j = i to 1 step -1
CFStringRef p
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
end if
next
SpeechSynthesizerRef ref = fn SpeechSynthesizerWithVoice( @"com.apple.speech.synthesis.voice.daniel.premium" )
fn SpeechSynthesizerStartSpeakingString( ref, mutStr )
end fn
 
fn OldLadySwallowedAFly
 
HandleEvents
</syntaxhighlight>
The following is both printed and recited back as audio in a proper English male voice.
{{out}}
<pre>
There was an old lady who swallowed a fly.
I don't know why she swallowed the fly — perhaps she'll die!
 
There was an old lady who swallowed a spider.
That wriggled and jiggled and tickled inside her.
She swallowed the spider to catch the fly.
I don't know why she swallowed the 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,
That wriggled and jiggled and tickled inside her.
She swallowed the spider to catch the fly.
I don't know why she swallowed the 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,
That wriggled and jiggled and tickled inside her.
She swallowed the spider to catch the fly.
I don't know why she swallowed the 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,
That wriggled and jiggled and tickled inside her.
She swallowed the spider to catch the fly.
I don't know why she swallowed the 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,
That wriggled and jiggled and tickled inside her.
She swallowed the spider to catch the fly.
I don't know why she swallowed the fly — perhaps she'll die!
 
There was an old lady who swallowed a cow.
I wonder how she swallowed a 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,
That wriggled and jiggled and tickled inside her.
She swallowed the spider to catch the fly.
I don't know why she swallowed the fly — perhaps she'll die!
 
There was an old lady who swallowed a horse...
She's dead, of course!
</pre>
 
 
 
 
=={{header|Go}}==
Line 2,086 ⟶ 2,240:
{{libheader|Icon Programming Library}}
[http://www.cs.arizona.edu/icon/library/src/procs/printf.icn printf.icn provides printf formatting]
 
=={{header|IS-BASIC}}==
<syntaxhighlight lang="is-basic">100 PROGRAM "OldLady.bas"
110 DIM A$(7),E$(7)
120 FOR N=0 TO 7
130 READ A$(N),E$(N)
140 NEXT
150 LET M$=CHR$(13):LET L$="There was an old lady who swallowed a "
160 TEXT 80:PRINT L$;A$(1);CHR$(241)
170 FOR C=1 TO 7
180 PRINT M$;M$;L$;A$(C);
190 IF C>1 THEN
200 PRINT ";";M$;E$(C);
210 IF C<N THEN
220 FOR B=C TO 2 STEP-1
230 PRINT M$;A$(0);A$(B);" to catch the ";A$(B-1);",;"(1+ABS(B=2));
240 IF B=3 THEN PRINT M$;" ";E$(2);
250 NEXT
260 END IF
270 ELSE
280 PRINT ",";
290 END IF
300 IF C<N THEN PRINT M$ E$(1);E$(0);
310 NEXT
320 PRINT M$;M$;L$;"horse...";M$;"She's dead, of course!"
330 DATA " She swallowed the "," - perhaps she'll die!"
340 DATA fly,I don't know why she swallowed a fly
350 DATA spider,"That wriggled and jiggled and tickled inside her,"
360 DATA bird,"How absurd to swallow a bird!"
370 DATA cat,"Fancy that to swallow a cat!"
380 DATA dog,"What a hog, to swallow a dog!"
390 DATA goat,"Just opened her throat and swallowwed a goat!"
400 DATA cow,"I don't know how she swallowed a cow!"</syntaxhighlight>
 
=={{header|J}}==
Line 2,113 ⟶ 2,300:
O'Horse'
e'She''s dead, of course!'</syntaxhighlight>
 
<pre style="height: 10em; overflow-y: scroll"> T
I know an old lady who swallowed a fly.
I don't know why she swallowed the fly.
Perhaps she'll die.
 
I know an old lady who swallowed a spider.
That wriggled and jiggled and tickled inside her.
She swallowed the spider to catch the fly.
I don't know why she swallowed the fly.
Perhaps she'll die.
 
I know an old lady who swallowed a Bird.
Quite 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 the fly.
Perhaps she'll die.
 
I know an old lady who swallowed a Cat.
Fancy that. To swallow 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 the fly.
Perhaps she'll die.
 
I know 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 the fly.
Perhaps she'll die.
 
I know an old lady who swallowed a Pig.
Her mouth was so big. To swallow a Pig.
She swallowed the Pig 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 the fly.
Perhaps she'll die.
 
I know an old lady who swallowed a Goat.
She just opened her throat. To swallow a Goat.
She swallowed the Goat to catch the Pig.
She swallowed the Pig 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 the fly.
Perhaps she'll die.
 
I know an old lady who swallowed a Cow.
I don't know how. To swallow a Cow.
She swallowed the Cow to catch the Goat.
She swallowed the Goat to catch the Pig.
She swallowed the Pig 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 the fly.
Perhaps she'll die.
 
I know an old lady who swallowed a Donkey.
It was rather wonky. To swallow a Donkey.
She swallowed the Donkey to catch the Cow.
She swallowed the Cow to catch the Goat.
She swallowed the Goat to catch the Pig.
She swallowed the Pig 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 the fly.
Perhaps she'll die.
 
I know an old lady who swallowed a Horse.
She's dead, of course!</pre>
 
=={{header|Java}}==
Line 2,145 ⟶ 2,416:
}
}</syntaxhighlight>
 
=={{header|jq}}==
'''Adapted from [[#Wren|Wren]]'''
{{works with|jq}}
'''Also works with gojq and fq, the Go implementations'''
<syntaxhighlight lang=jq>
def animals:
["fly", "spider", "bird", "cat", "dog", "goat", "cow", "horse"];
 
def phrases: [
null,
"That wriggled and jiggled and tickled inside her",
"How absurd to swallow a bird",
"Fancy that to swallow a cat",
"What a hog, to swallow a dog",
"She just opened her throat and swallowed a goat",
"I don't know how she swallowed a cow",
"\n ...She's dead of course"
];
 
def sing:
def cond(q; x): select(q) | x;
range(0;8)
| "There was an old lady who swallowed a \(animals[.]);",
cond(. > 0; "\(phrases[.])"),
cond(. < 7;
"",
cond(. > 0;
range(.; 0; -1) as $j
| " She swallowed the \(animals[$j]) to catch the \(
animals[$j - 1])\(if $j < 3 then ";" else "," end)",
cond($j == 2; " \(phrases[1])!") ),
" I don't know why she swallowed a fly - Perhaps she'll die!\n" );
 
sing
</syntaxhighlight>
{{output}}
As for [[#Wren|Wren]].
 
=={{header|Julia}}==
Line 3,584 ⟶ 3,893:
("IK" "I know an old lady who swallowed a") ("SW" "She swallowed the")
("SS" "she swallowed") ("CA" "to catch the") ("XX" "Perhaps she'll die")
("C" "cow") ("G" "goat") ("D" "dog") ("T@" "cat") ("R" "bird")
("S $" "spider ") ("F" "fly"))
@(bind lastverse
("IK C"
Line 3,591 ⟶ 3,900:
"SW C CA G"
"SW G CA D"
"SW D CA T@"
"SW T@ CA R"
"SW R CA S$"
"SW S$ CA F"
"But I don't know why SS that F"
"XX"
Line 3,603 ⟶ 3,912:
("G: Opened her throat and down went the G!"
"D: What a hog to swallow a D!"
"T@: Imagine that! She swallowed a T@!"
"R: How absurd to swallow a R!"
"S$: That wriggled and jiggled and tickled inside her"
"F: But I don't know why SS the F"))
@(define expand_backwards (song lengthened_song done))
Line 3,759 ⟶ 4,068:
next
</syntaxhighlight>
=={{header|V (Vlang)}}==
<syntaxhighlight lang="v (vlang)">const (
name = 0
lyric = 1
Line 3,849 ⟶ 4,158:
=={{header|Wren}}==
{{trans|Kotlin}}
<syntaxhighlight lang="ecmascriptwren">var animals = ["fly", "spider", "bird", "cat","dog", "goat", "cow", "horse"]
 
var phrases = [
Line 3,880 ⟶ 4,189:
 
sing.call()</syntaxhighlight>
 
=={{header|XPL0}}==
{{trans|C}}
<syntaxhighlight lang "XPL0">include xpllib; \For Print
 
int Animals, Verses, I, J;
[Animals:= ["fly", "spider", "bird", "cat", "dog", "goat", "cow", "horse"];
Verses:= [
"I don't know why she swallowed that fly.^m^jPerhaps she'll die^m^j",
"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" ];
for I:= 0 to 8-1 do
[Print("There was an old lady who swallowed a %s\n%s\n", Animals(I), Verses(I));
J:= I;
while J > 0 and I < 8-1 do
[Print("She swallowed the %s to catch the %s\n", Animals(J), Animals(J-1));
if J = 1 then Print("%s\n", Verses(0));
J:= J-1;
]
]
]</syntaxhighlight>
 
=={{header|Z80 Assembly}}==
Anonymous user