Anonymous user
Old lady swallowed a fly: Difference between revisions
m
→{{header|Elena}}
Not a robot (talk | contribs) (Add Draco) |
imported>Arakov |
||
(17 intermediate revisions by 14 users not shown) | |||
Line 13:
{{trans|Python}}
<
(‘fly’, ‘I don't know why she swallowed a fly, perhaps she'll die.’),
(‘spider’, ‘It wiggled and jiggled and tickled inside her.’),
Line 36:
I animal != ‘fly’
print(animals[0][1])
print()</
=={{header|8080 Assembly}}==
<
mvi c,-1 ; C = verse counter
verse: inr c
Line 110:
swlw1: db 'She swallowed the $'
swlw2: db ' to catch the $'
comma: db ',',13,10,'$'</
=={{header|8086 Assembly}}==
<
org 100h
section .text
Line 177:
swlw1: db 'She swallowed the $'
swlw2: db ' to catch the $'
comma: db ',',13,10,'$'</
=={{header|Ada}}==
<
procedure Swallow_Fly is
Line 237:
Put_Line("There was an old lady who swallowed a horse ...");
Put_Line("She's dead, of course!");
end Swallow_Fly;</
=={{header|ALGOL 68}}==
Line 244:
{{works with|ALGOL 68G|Any - tested with release [http://sourceforge.net/projects/algol68/files/algol68g/algol68g-1.18.0/algol68g-1.18.0-9h.tiny.el5.centos.fc11.i386.rpm/download 1.18.0-9h.tiny].}}
{{wont work with|ELLA ALGOL 68|Any (with appropriate job cards) - tested with release [http://sourceforge.net/projects/algol68/files/algol68toc/algol68toc-1.8.8d/algol68toc-1.8-8d.fc9.i386.rpm/download 1.8-8d] - due to extensive use of '''format'''[ted] ''transput''.}}
<
STRING sw=" swallow ",swd=sw[:UPB sw-1]+"ed ", tsa=". To"+sw+"a";
Line 277:
vs("Cow",("I don't know how",tsa));
vs("Donkey",("It was rather wonky",tsa));
vs("Horse","She's dead, of course!")</
===Using a dictionary===
Line 283:
{{works with|ALGOL 68G|Any - tested with release [http://sourceforge.net/projects/algol68/files/algol68g/algol68g-1.18.0/algol68g-1.18.0-9h.tiny.el5.centos.fc11.i386.rpm/download 1.18.0-9h.tiny].}}
{{wont work with|ELLA ALGOL 68|Any (with appropriate job cards) - tested with release [http://sourceforge.net/projects/algol68/files/algol68toc/algol68toc-1.8.8d/algol68toc-1.8-8d.fc9.i386.rpm/download 1.8-8d] - due to extensive use of '''format'''[ted] ''transput''.}}
<
STRING a="WBXAY",b="WCXBY",c="WDXCY",d="WEXDY",
Line 321:
OD;
print(new line)
OD</
=={{header|APL}}==
{{works with|Dyalog APL}}
<
N←⎕TC[3]
a←'fly' 'spider' 'bird' 'cat' 'dog' 'goat' 'cow' 'horse'
Line 344:
}¨⌽1↓⍳⍵
}¨⍳8
}</
=={{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
_start: eor r8,r8,r8 @ Verse counter
verse: add r8,r8,#1 @ Next verse
Line 414 ⟶ 431:
swa1: .asciz "She swallowed the "
swa2: .asciz " to catch the "
comma: .asciz ",\n" </
=={{header|AutoHotkey}}==
{{works with|AutoHotkey 1.1}}
<
, ["spider", "That wriggled and jiggled and tickled inside her"]
, ["bird", "Quite absurd"]
Line 436 ⟶ 453:
}
MsgBox, % Output</
=={{header|AWK}}==
<syntaxhighlight lang="awk">
# syntax: GAWK -f OLD_LADY_SWALLOWED_A_FLY.AWK
BEGIN {
Line 473 ⟶ 490:
exit(0)
}
</syntaxhighlight>
=={{header|Babel}}==
<
(fly
Line 520 ⟶ 537:
("spider" "That wriggled and jiggled and tickled inside her")
("fly" " "))))
</syntaxhighlight>
=={{header|Batch File}}==
<
setlocal enabledelayedexpansion
Line 568 ⟶ 585:
)
:done
pause>nul&exit/b 0</
=={{header|BBC BASIC}}==
This prints the lyrics from the Wikipedia page, more or less. I don't know anything about goats and donkeys and the like.
<
DIM swallowings$(6, 1)
swallowings$() = "fly", "+why", "spider", "That wriggled and wiggled and tickled inside her", "bird", ":How absurd", "cat", ":Fancy that", "dog", ":What a hog", "cow", "+how", "horse", "She's dead, of course"
Line 599 ⟶ 616:
PRINT observation$; "!"
ENDCASE
ENDPROC</
=={{header|BCPL}}==
<
let animal(n) =
Line 631 ⟶ 648:
$)
let start() be for n=0 to 7 do verse(n)</
=={{header|Befunge}}==
We start with a collection of reusable phrases stored as a linked list. We then build up the sequence of indices into that list necessary to produce the song (this step is largely programmatic, because of the repetitive nature, although some of the verses require special case handling). Finally we iterate over the indices and print out the associated phrases.
<
>-#2:#\8#1`#:|#-1:-1\7_^#`g00:+<>\#%"O"/#::$#<3#$+g48*-v^\,+*+ 55!:*!!-"|":g+3<
>$ 36 26 58 49 81 36 26 10 \1-:#^\_^#:-1\+<00_@#:>#<$<
Line 644 ⟶ 661:
.|Fancy that$Dog-.|What a hog$Pig7.|Her mouth was so big%Goat=.|She just opened
her throat$Cow3.|I don't know how'Donkey6.|It was rather wonky&Horse:.|She's d
ead, of course!|</
=={{header|C}}==
<
static char const *animals[] = {
"fly",
Line 682 ⟶ 699:
}
}
}</
=={{header|C sharp|C#}}==
<
namespace OldLady
Line 725 ⟶ 742:
}
}
}</
=={{header|C++}}==
{{trans|C#}}
<
const char *CREATURES[] = { "fly", "spider", "bird", "cat", "dog", "goat", "cow", "horse" };
Line 756 ⟶ 773:
return 0;
}</
{{out}}
<pre>There was an old lady who swallowed a fly
Line 817 ⟶ 834:
=={{header|CLU}}==
<
rep = null
Line 857 ⟶ 874:
start_up = proc ()
old_lady$swallow(stream$primary_output())
end start_up</
=={{header|COBOL}}==
<
PROGRAM-ID. OLD-LADY.
Line 950 ⟶ 967:
DISPLAY LINE-OUT.
</syntaxhighlight>
=={{header|Commodore BASIC}}==
Line 958 ⟶ 975:
===Commodore BASIC (No Sound)===
<
1 rem rosetta code
2 rem old lady who swallowed a fly
Line 992 ⟶ 1,009:
1070 data "cow","I don't know how she swallowed a cow!"
1080 data "horse","...She died, of course!"
</syntaxhighlight>
===Commodore 64===
Sound must be played to the Commodore 64 SID chip through direct register access, therefore, the sound table is two-dimensional to account for the high byte and low byte of the appropriate frequencies.
<
1 rem rosetta code
2 rem old lady who swallowed a fly - c64
Line 1,063 ⟶ 1,080:
2550 for i=1 to 8:for j=1 to 3:read mu$(i,j):next j:next i
2599 return
</syntaxhighlight>
===Commodore Plus/4===
BASIC 3.5 on the Commodore Plus/4 at least features the SOUND command which simplifies getting the sound processor to play notes, however, a "tuned" sound table still needs to be defined with the appropriate frequencies.
<
1 rem rosetta code
2 rem old lady who swallowed a fly - plus/4
Line 1,135 ⟶ 1,152:
2550 for i=1 to 8:for j=1 to 3:read mu$(i,j):next j:next i
2599 return
</syntaxhighlight>
===Commodore 128===
BASIC 7.0 on the Commodore 128 features a robust PLAY command which will interpret strings of macro commands for commanding the SID processor. This all but eliminates the bulk of the note playing routines. Note the data statements are slightly different as the macros for note duration are different. The 128 uses '''i''', '''q''', and '''h''' for ''eighth'', ''quarter'', and ''half'' notes respectively, while the 64 and Plus/4 examples were coded to use '''8''', '''4''', and '''2''' as it was simpler to use for math operations, rather than an additional look-up table.
<
1 rem rosetta code
2 rem old lady who swallowed a fly - c128
Line 1,191 ⟶ 1,208:
2520 play "v1o4t0u5"
2599 return
</syntaxhighlight>
=={{header|Common Lisp}}==
A rather iterative, rather than recursive solution. The lyrics match the original Burl Ives recording (not the later animated cartoon):
<
(defun what (verse) (first verse))
(defun remark (verse) (second verse))
Line 1,232 ⟶ 1,249:
(if (always v)
(format t "~a~a~%" (if (= j 0) "But " "") (remark v))))))
(format t "Perhaps she'll die. ~%~%"))))))</
{{Out}}
Line 1,263 ⟶ 1,280:
=={{header|Cowgol}}==
<
var animals: [uint8][] := {
Line 1,303 ⟶ 1,320:
i := i + 1;
end loop;</
=={{header|D}}==
{{trans|C}}
<
immutable data = [
Line 1,335 ⟶ 1,352:
void main() {
data[0].oldLady;
}</
A more structured alternative version:
<
immutable struct T {
Line 1,378 ⟶ 1,395:
"Perhaps she'll die.\n".writeln;
}
}</
=={{header|Draco}}==
<
case n
incase 0: "fly"
Line 1,425 ⟶ 1,442:
byte n;
for n from 0 upto 7 do verse(n) od
corp</
=={{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
<
const Creatures = new string[]{"fly", "spider", "bird", "cat", "dog", "goat", "cow", "horse"};
Line 1,446 ⟶ 1,483:
public program()
{
for(int i := 0
{
console
Line 1,454 ⟶ 1,491:
if(i != 0 && i != Creatures.Length - 1)
{
for(int j := i
{
console.printLineFormatted("She swallowed the {0} to catch the {1}",Creatures[j],Creatures[j - 1])
Line 1,464 ⟶ 1,501:
console.writeLine()
}
}</
=={{header|Elixir}}==
{{trans|Ruby}}
<
@descriptions [
fly: "I don't know why S",
Line 1,515 ⟶ 1,552:
end
Old_lady.swallowed</
=={{header|Factor}}==
Windows users should put zlib1.dll[http://downloads.factorcode.org/dlls/] to factor folder.
<
"c%1E4%WlIU5WMphn^P`UexSD=s^-?Jk$NVE7-Gs=fQ9_`T}Y~ggi4hvMSb{SX}vpQXJ;^Yqok7%xd(0
Line 1,528 ⟶ 1,565:
<}rUt#FCDtKB9S`Y4jg+0PuB?Qt-&(11p?caq^S=1C`$D1fa<y6|YD*77a{4949T_-MVet;6abaEn"
base85> 3215 <compressed> uncompress >string print</
=={{header|Forth}}==
swallow-addr is obviously a good candidate for an object, but Forth has many OO candidates - we won't settle that argument here.
<
dup c, here swap dup allot move ;
Line 1,585 ⟶ 1,622:
first @ begin dup verse cr >next dup 0= until drop
cr ." There was an old lady who swallowed a horse..."
cr ." She's dead, of course!" ;</
=={{header|Fortran}}==
<syntaxhighlight lang="fortran">
program fly
!A program to print the "Old lady swallowed a fly" poem
Line 1,627 ⟶ 1,664:
end program fly
</syntaxhighlight>
=={{header|FreeBASIC}}==
<
{ "fly", "I don't know why she swallowed a fly - Perhaps she'll die!" },_
{ "spider", "That wriggled and jiggled and tickled inside her!" },_
Line 1,652 ⟶ 1,689:
next countdown
print
next verse</
=={{header|Free Pascal}}==
<
in Rosetta Code. It formats the lyrics like the Wikipedia one *)
program OldLady;
Line 1,735 ⟶ 1,772:
PrintSong;
end.
</syntaxhighlight>
=={{header|Frege}}==
Line 1,743 ⟶ 1,780:
Nearly identical to the Haskell. Only the first line of the program is different.
<
import Data.List
Line 1,783 ⟶ 1,820:
song = concatMap verse $ tail $ reverse $ tails animals
main = putStr $ unlines song</
=={{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}}==
[https://play.golang.org/p/OV3YJSWxaJP Go Playground]
<
import "fmt"
Line 1,824 ⟶ 1,978:
fmt.Println(animals[0][lyric] + "\n")
}
}</
=={{header|Haskell}}==
<
animals :: [String]
Line 1,856 ⟶ 2,010:
putStr $
concatMap unlines $
zipWith (:) beginnings $ reverse $ ([] :) (tails lastVerse)</
{{out}}<pre>There was an old lady who swallowed a fly.
I don't know why she swallowed a fly.
Line 1,923 ⟶ 2,077:
And a variation on this theme (a little more disaggregated):
<
import Data.Map.Strict (Map, fromList, lookup)
import Data.List (inits, intercalate)
Line 1,984 ⟶ 2,138:
comments :: Map String String
comments = fromList courses</
{{Out}}
<pre>There was an old lady who swallowed a fly;
Line 2,050 ⟶ 2,204:
=={{header|Icon}} and {{header|Unicon}}==
This version isn't as compressed as some of the others but it is very straightforward to modify. Just add a new long and terse verse entry and amend the line marked order. This uses a feature of Icon/Unicon that allows procedures to be called with a list datatype instead of an argument list, so we just pre-build argument lists for printf.
<
verse := table() # arglists for printf - [1] long asides and [2] terse joiners
Line 2,081 ⟶ 2,235:
end
link printf</
Sample output omitted.
{{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}}==
This defines T to be the required text.
<
e=:3 :'T=:T,y,LF'
E=:e@,&'.'
Line 2,112 ⟶ 2,299:
'Donkey'N'It was rather wonky'
O'Horse'
e'She''s dead, of course!'</
<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}}==
{{Trans|C| via [[#D|D]]}}
<
final static String[] data = {
Line 2,144 ⟶ 2,415:
oldLady(data[0], false);
}
}</
=={{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}}==
{{works with|Julia|0.6}}
<
b64 = b"""eNrtVE1rwzAMvedXaKdeRn7ENrb21rHCzmrs1m49K9gOJv9+cko/HBcGg0LHcpOfnq2np0QL
Line 2,158 ⟶ 2,467:
Mz3XkPBc/TSN3yxGiqMiipHRekycK0ZwMhM8jerGC9zuZaoTho3kMKSfJjLaF8v8wLzmXMqM
zJvGew/jnZPzclA08yAkikegDTTUMfzwDXBcwoE="""
println(String(transcode(ZlibDecompressor(), base64decode(b64))))</
<
("fly", "I don't know why she swallowed a fly, perhaps she'll die."),
("spider", "It wiggled and jiggled and tickled inside her."),
Line 2,181 ⟶ 2,490:
if animal != "fly" println(animals[1][2]) end # fly lyric
println() # new line
end</
=={{header|Kotlin}}==
<
val animals = listOf("fly", "spider", "bird", "cat","dog", "goat", "cow", "horse")
Line 2,218 ⟶ 2,527:
fun main(args: Array<String>) {
sing()
}</
=={{header|Lambdatalk}}==
<
{def A {A.new fly spider bird cat dog goat cow horse}}
-> A
Line 2,295 ⟶ 2,604:
There was an old lady who swallowed a horse
She's dead of course
</syntaxhighlight>
=={{header|Liberty BASIC}}==
<syntaxhighlight lang="lb">
'[RC] Old lady swallowed a fly
'http://rosettacode.org/wiki/Old_lady_swallowed_a_fly
Line 2,344 ⟶ 2,653:
end
</syntaxhighlight>
=={{header|Logo}}==
<
; animal inc comment
[fly 2 [I don't know why she swallowed that fly]]
Line 2,381 ⟶ 2,690:
]
bye</
=={{header|Lua}}==
<
phrases = {
"",
Line 2,413 ⟶ 2,722:
end
io.write("I don't know why she swallowed a fly - Perhaps she'll die!\n\n")
end</
=={{header|MAD}}==
<
INTERNAL FUNCTION(V)
Line 2,458 ⟶ 2,767:
VERSE WHENEVER J.LE.2, VERSE.(J-1)
END OF PROGRAM </
=={{header|Maple}}==
<
phrases := ["I don't know why she swallowed a fly, perhaps she'll die!",
"That wriggled and wiggled and tiggled inside her.",
Line 2,479 ⟶ 2,788:
printf("\n");
end if;
end do;</
{{out}}
<pre>
Line 2,525 ⟶ 2,834:
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<
"horse"};
notes = {"", "That wiggled and jiggled and tickled inside her.\n",
Line 2,541 ⟶ 2,850:
StringJoin @@ ("She swallowed the " <> animals[[#]] <>
" to catch the " <> animals[[# - 1]] <> ".\n" & /@
Range[#, 2, -1]) <> notes[[9]]] & /@ Range[8])];</
{{out}}
<pre>There was an old lady who swallowed a fly.
Line 2,602 ⟶ 2,911:
=={{header|Mercury}}==
<
:- interface.
:- import_module io.
Line 2,674 ⟶ 2,983:
main(!IO) :-
swallowed(fly, !IO).</
=={{header|Modula-2}}==
<
FROM FormatString IMPORT FormatString;
FROM Terminal IMPORT WriteString,WriteLn,ReadChar;
Line 2,728 ⟶ 3,037:
ReadChar
END OldLady.</
=={{header|Nanoquery}}==
{{trans|Ursa}}
<
creatures = {"fly", "spider", "bird", "cat", "dog", "goat", "cow", "horse"}
comments = {"I don't know why she swallowed that fly.\nPerhaps she'll die\n",\
Line 2,755 ⟶ 3,064:
end
input()</
=={{header|Nim}}==
{{trans|Python}}
{{libheader|nim-lang/zip}}
<
const b64 = """
Line 2,771 ⟶ 3,080:
zJvGew/jnZPzclA08yAkikegDTTUMfzwDXBcwoE="""
echo b64.decode.uncompress()</
=={{header|OCaml}}==
===Using a dictionary===
Only one minimalist line of code (the last line):
<
"I know an old lady who swallowed a "; "fly"; ".\n";
"I don't know why she swallowed the fly.\nPerhaps she'll die.\n\n";
Line 2,807 ⟶ 3,116:
[23] ;;
List.iter (fun i -> print_string d.(i)) s</
===Using dictionary based decompression===
{{trans|D}}
Here we use the function <code ocaml>String.fold_left</code> [http://ocaml-extlib.googlecode.com/svn/doc/apiref/ExtString.String.html#VALfold_left 1] which is not available in the standard library but in the [http://code.google.com/p/ocaml-extlib/ extlib]:
<
"_ha _c _e _p,\nQuite absurd_f_p;_`cat,\nFancy that_fcat;_j`dog,\nWhat a hog_\
fdog;_l`pig,\nHer mouth_qso big_fpig;_d_r,\nShe just opened her throat_f_r;_i\
Line 2,829 ⟶ 3,138:
let _ =
old_lady dict.(0) false</
===Using Logic===
<
[| "fly"; "spider"; "bird"; "cat"; "dog"; "pig"; "goat"; "cow"; "donkey" |]
Line 2,862 ⟶ 3,171:
for i = 0 to 8 do f i done;
p "There was an old lady who swallowed a horse...\n\
She's dead, of course!"</
=={{header|Perl}}==
Using string subst:<
"fly",
"spider/That wriggled and jiggled and tickled inside her.\n",
Line 2,896 ⟶ 3,205:
s/:.*/--\nShe's dead, of course!\n/s;
print;
}</
Using compression:
(Assumes a Unix-like OS and the availability of the uudecode and bunzip2 utilities).
<
print OUT <DATA> and
close OUT;
Line 2,916 ⟶ 3,225:
FeXUOI8486Wvor1zajqPDfpwnrn2jOzvo8hkOPrpVajlwnjqPfIry5c0TbKL
559fx8xqpsquRaFYV9I9fT6p7RrI/Gv/F3JFOFCQRJtf/Q==
====</
=={{header|Phix}}==
{{Trans|Ada}}
<!--<syntaxhighlight lang="phix">(phixonline)-->
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #004080;">sequence</span> <span style="color: #000000;">lines</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{</span><span style="color: #008000;">"Perhaps she'll die!\n"</span><span style="color: #0000FF;">},</span> <span style="color: #000000;">animals</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{}</span>
<span style="color: #008080;">procedure</span> <span style="color: #000000;">swallow</span><span style="color: #0000FF;">(</span><span style="color: #004080;">string</span> <span style="color: #000000;">animal</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">second_line</span><span style="color: #0000FF;">,</span> <span style="color: #004080;">integer</span> <span style="color: #000000;">permanent_second_line</span><span style="color: #0000FF;">=</span><span style="color: #004600;">TRUE</span><span style="color: #0000FF;">)</span>
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"There was an old lady who swallowed a %s,\n%s\n"</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">animal</span><span style="color: #0000FF;">,</span><span style="color: #000000;">second_line</span><span style="color: #0000FF;">})</span>
<span style="color: #008080;">if</span> <span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">animals</span><span style="color: #0000FF;">)!=</span><span style="color: #000000;">0</span> <span style="color: #008080;">then</span>
<span style="color: #000000;">lines</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">prepend</span><span style="color: #0000FF;">(</span><span style="color: #000000;">lines</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">sprintf</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"She swallowed the %s to catch the %s,\n"</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">animal</span><span style="color: #0000FF;">,</span><span style="color: #000000;">animals</span><span style="color: #0000FF;">[$]}))</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"%s\n"</span><span style="color: #0000FF;">,{</span><span style="color: #7060A8;">join</span><span style="color: #0000FF;">(</span><span style="color: #000000;">lines</span><span style="color: #0000FF;">,</span><span style="color: #008000;">""</span><span style="color: #0000FF;">)})</span>
<span style="color: #008080;">if</span> <span style="color: #000000;">permanent_second_line</span> <span style="color: #008080;">then</span>
<span style="color: #000000;">lines</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">prepend</span><span style="color: #0000FF;">(</span><span style="color: #000000;">lines</span><span style="color: #0000FF;">,</span><span style="color: #000000;">second_line</span><span style="color: #0000FF;">&</span><span style="color: #008000;">"\n"</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #000000;">animals</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">append</span><span style="color: #0000FF;">(</span><span style="color: #000000;">animals</span><span style="color: #0000FF;">,</span><span style="color: #000000;">animal</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">procedure</span>
<span style="color: #008080;">procedure</span> <span style="color: #000000;">swallow_all</span><span style="color: #0000FF;">(</span><span style="color: #004080;">sequence</span> <span style="color: #000000;">all</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">for</span> <span style="color: #000000;">i</span><span style="color: #0000FF;">=</span><span style="color: #000000;">1</span> <span style="color: #008080;">to</span> <span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">all</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">do</span>
<span style="color: #004080;">string</span> <span style="color: #0000FF;">{</span><span style="color: #000000;">animal</span><span style="color: #0000FF;">,</span><span style="color: #000000;">line2</span><span style="color: #0000FF;">}</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">all</span><span style="color: #0000FF;">[</span><span style="color: #000000;">i</span><span style="color: #0000FF;">]</span>
<span style="color: #000000;">swallow</span><span style="color: #0000FF;">(</span><span style="color: #000000;">animal</span><span style="color: #0000FF;">,</span> <span style="color: #7060A8;">sprintf</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"%s, %s a %s;"</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">line2</span><span style="color: #0000FF;">,</span><span style="color: #008080;">iff</span><span style="color: #0000FF;">(</span><span style="color: #000000;">animal</span><span style="color: #0000FF;">=</span><span style="color: #008000;">"cow"</span><span style="color: #0000FF;">?</span><span style="color: #008000;">"she swallowed"</span><span style="color: #0000FF;">:</span><span style="color: #008000;">"to swallow"</span><span style="color: #0000FF;">),</span><span style="color: #000000;">animal</span><span style="color: #0000FF;">}),</span> <span style="color: #004600;">FALSE</span><span style="color: #0000FF;">);</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">procedure</span>
<span style="color: #000000;">swallow</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"fly"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"But I don't know why she swallowed the fly,"</span><span style="color: #0000FF;">);</span>
<span style="color: #000000;">swallow</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"spider"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"That wriggled and jiggled and tickled inside her;"</span><span style="color: #0000FF;">);</span>
<span style="color: #000000;">swallow_all</span><span style="color: #0000FF;">({{</span><span style="color: #008000;">"bird"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"Quite absurd"</span><span style="color: #0000FF;">},{</span><span style="color: #008000;">"cat"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"Fancy that"</span><span style="color: #0000FF;">},{</span><span style="color: #008000;">"dog"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"What a hog"</span><span style="color: #0000FF;">},</span>
<span style="color: #0000FF;">{</span><span style="color: #008000;">"pig"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"Her mouth was so big"</span><span style="color: #0000FF;">},{</span><span style="color: #008000;">"goat"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"She just opened her throat"</span><span style="color: #0000FF;">},</span>
<span style="color: #0000FF;">{</span><span style="color: #008000;">"cow"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"I don't know how"</span><span style="color: #0000FF;">},{</span><span style="color: #008000;">"donkey"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"It was rather wonky"</span><span style="color: #0000FF;">}})</span>
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"There was an old lady who swallowed a horse ...\nShe's dead, of course!"</span><span style="color: #0000FF;">)</span>
<!--</syntaxhighlight>-->
=={{header|PHP}}==
<
$swallowed = array(
Line 2,988 ⟶ 3,300:
else
print "Perhaps she'll die." . "\n\n";
}</
=={{header|PicoLisp}}==
{{trans|C}}
<
`(chop
"_ha _c _e _p,/Quite absurd_f_p;_`cat,/Fancy that_fcat;_j`dog,\
Line 3,033 ⟶ 3,345:
Flg )
(oldLady (car *Dict))</
=={{header|PL/M}}==
<
/* CP/M CALL */
Line 3,098 ⟶ 3,410:
CALL BDOS(0,0);
EOF</
=={{header|PowerShell}}==
<
$lines = @(
'fly/'
Line 3,133 ⟶ 3,445:
"Perhaps she'll die."
""
}</
=={{header|Python}}==
<
b64 = b'''
Line 3,146 ⟶ 3,458:
Mz3XkPBc/TSN3yxGiqMiipHRekycK0ZwMhM8jerGC9zuZaoTho3kMKSfJjLaF8v8wLzmXMqM
zJvGew/jnZPzclA08yAkikegDTTUMfzwDXBcwoE='''
print(zlib.decompress(base64.b64decode(b64)).decode("utf-8", "strict"))</
<
("fly", "I don't know why she swallowed a fly, perhaps she'll die."),
("spider", "It wiggled and jiggled and tickled inside her."),
Line 3,167 ⟶ 3,479:
if animal != "fly": print(animals[0][1]) # fly lyric
print() # new line</
=={{header|R}}==
<
c("fly", "I don't know why she swallowed a fly, perhaps she'll die."),
c("spider", "It wiggled and jiggled and tickled inside her."),
Line 3,202 ⟶ 3,514:
oldladysnack <- oldladysnack + 1
}
</syntaxhighlight>
=={{header|Racket}}==
<
#lang at-exp racket
Line 3,230 ⟶ 3,542:
@line{}
(loop more (cons animal seen)))])))
</syntaxhighlight>
Alternative solution:
<
#lang s-exp framework/private/decode
7VK7TsQwEOz9FcM1AcncZyCoQaLey/piCyuObJ+s/D3rXHj4lIIKgaCItJkZ7cyOfM0uTZ5m
Line 3,239 ⟶ 3,551:
U+SaYuVXditxxdu8b338rOvEUas7GvuVa44Tcuu2/qz7CHuu6PeWwGHQ6rmiBCtz24KwWy0I
3KZdqvwDbfWhXPhY+S59RLX5dkTapF66/2/3fYMNMZklVJfAhlgjHKW2k8B7tbtRrw==
</syntaxhighlight>
=={{header|Raku}}==
(formerly Perl 6)
<syntaxhighlight lang="raku"
fly => " I don't know why S—",
spider => " That wriggled and jiggled and tickled inside her.",
Line 3,267 ⟶ 3,579:
@history.unshift($_) if @history < 5;
@history.unshift("X to catch the $victim,");
}</
And that's how I larned it!
=={{header|REXX}}==
<
sw= 79 /*the width of the terminal screen, -1.*/
@.=; @.1 = "I don't know why she swallowed a fly,"
Line 3,294 ⟶ 3,606:
say center(@.1, sw)
say center("I guess she'll die.", sw)
end /*j*/ /*stick a fork in it, we're all done. */</
{{out|output|text= (with the lyrics being centered):}}
<pre>
Line 3,362 ⟶ 3,674:
=={{header|Ruby}}==
<
:fly => "I don't know why S",
:spider => "That wriggled and jiggled and tickled inside her.",
Line 3,393 ⟶ 3,705:
print "Perhaps she'll die.\n\n"
end</
=={{header|Rust}}==
[https://play.rust-lang.org/?gist=294c9e29f206d7c8d8028aa5e7002d9a&version=nightly Rust Playground]
<
use Action::*;
Line 3,428 ⟶ 3,740:
println!("Perhaps she'll die.\n");
}
}</
=={{header|Scala}}==
<
val verses = List(
Line 3,457 ⟶ 3,769:
println
}
}</
{{out}}
<pre>There was an old lady who swallowed a fly,
Line 3,486 ⟶ 3,798:
=={{header|Seed7}}==
<
const array array string: verses is [] (
Line 3,519 ⟶ 3,831:
end if;
end for;
end func;</
=={{header|Sidef}}==
{{trans|Raku}}
<
:fly: " I don't know why S—",
:spider: " That wriggled and jiggled and tickled inside her.",
Line 3,550 ⟶ 3,862:
history.len < 5 && history.unshift(verse);
history.unshift("X to catch the #{victim},");
};</
=={{header|Tcl}}==
Because the song is highly repetitive, it compresses wonderfully.
<
puts [zlib inflate [binary decode base64 "
Line 3,565 ⟶ 3,877:
nCtGcDITPI3qxgvc7mWqE4aN5DCknyYy2hfL/MC85lzKjMybxnsP452T83JQNPMg
JIpHoA001DH88A0=
"]]</
=={{header|TXR}}==
Line 3,578 ⟶ 3,890:
Note one detail: in the first verse we have "... don't know why she swallowed the fly". But in subsequent verses it is
"that fly" not "the fly". So we do a lookup on the fly also to substitute the appropriate line, and in the fly case we skip the original line (see the first <code>@(maybe)</code>).
<
("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") ("
("
@(bind lastverse
("IK C"
Line 3,588 ⟶ 3,900:
"SW C CA G"
"SW G CA D"
"SW D CA
"SW
"SW R CA
"SW
"But I don't know why SS that F"
"XX"
Line 3,600 ⟶ 3,912:
("G: Opened her throat and down went the G!"
"D: What a hog to swallow a D!"
"
"R: How absurd to swallow a R!"
"
"F: But I don't know why SS the F"))
@(define expand_backwards (song lengthened_song done))
Line 3,660 ⟶ 3,972:
@song
@ (end)
@(end)</
=={{header|UNIX Shell}}==
{{works_with|Bash}}
<
comments=("I don't know why she swallowed that fly"
"That wriggled and jiggled and tickled inside her"
Line 3,692 ⟶ 4,004:
echo
fi
done</
=={{header|Ursa}}==
{{trans|C#}}
<
append "She swallowed the " " to catch the " reason
append "fly" "spider" "bird" "cat" "dog" "goat" "cow" "horse" creatures
Line 3,721 ⟶ 4,033:
end for
end for
in string console</
=={{header|VBScript}}==
<syntaxhighlight lang="vb">
a=array( _
array("fly",""),_
array("spider","That wiggled and jiggled and tickled inside her"), _
array("bird","How absurd, to swallow a bird"), _
array("cat","Imagine that. She swallowed a cat"), _
array("dog","What a hog to swallow a dog"), _
array("goat","She just opened her throat and swallowed that goat"),_
array("cow","I don't know how she swallowed that cow"), _
array("horse","She's dead of course...")_
)
b1="I don't know why she swallowed the fly." & vbcrlf &"Perhaps she'll die."& vbcrlf
b2="There was an old lady who swallowed a @ani@."
b3="She swallowed the @ani@ to catch the @pani@."
sub print(s): wscript.stdout.write(s) & vbcrlf : end sub
for i=0 to ubound(a)
ani=a(i)(0)
print replace(b2,"@ani@",ani)
print a(i)(1)
if i=ubound(a) then exit for 'horse
for j= i-1 to 0 step -1
oldani=ani
ani=a(j)(0)
print replace(replace(b3,"@ani@",oldani),"@pani@",ani)
if j=1 then print a(1)(1) ' spider
next
print b1
next
</syntaxhighlight>
=={{header|V (Vlang)}}==
<syntaxhighlight lang="v (vlang)">const (
name = 0
lyric = 1
animals = [
["fly", "I don't know why she swallowed a fly. Perhaps she'll die."],
["spider", "That wiggled and jiggled and tickled inside her."],
["bird", "How absurd, to swallow a bird."],
["cat", "Imagine that, she swallowed a cat."],
["dog", "What a hog, to swallow a dog."],
["goat", "She just opened her throat and swallowed that goat."],
["cow", "I don't know how she swallowed that cow."],
["horse", "She's dead, of course."],
]
)
fn main() {
for i, animal in animals {
println("There was an old lady who swallowed a ${animal[name]},")
if i > 0 {
println(animal[lyric])
}
// Swallowing the last animal signals her death, cutting the
// lyrics short.
if i+1 == animals.len {
break
}
for j := i; j > 0; j-- {
println("She swallowed the ${animals[j][name]} to catch the ${animals[j-1][name]},")
}
println("${animals[0][lyric]}\n")
}
}</syntaxhighlight>
{{out}}
<pre>
There was an old lady who swallowed a fly,
I don't know why she swallowed a 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 a 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 a 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 a 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 a 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 a 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 a fly. Perhaps she'll die.
There was an old lady who swallowed a horse,
She's dead, of course.
</pre>
=={{header|Wren}}==
{{trans|Kotlin}}
<
var phrases = [
Line 3,755 ⟶ 4,188:
}
sing.call()</
=={{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}}==
Line 3,761 ⟶ 4,220:
Press any key to print each verse. After the last verse, press any key to return to BASIC.
<
PrintChar equ &BB5A
Line 3,930 ⟶ 4,389:
byte " to catch the ",0
Song_NewLine:
byte 13,10,0 ;control codes for a new line.</
=={{header|zkl}}==
{{trans|Tcl}}
Uncompresses the base64 encoded gziped text of the song. Uses shared libraries zlib and msg hashing for the codecs.
<
text:=
"eJztlE1uwyAQhdflFOOVNyhXyLap1FV7AWKIoaFMBFjIt++M7YVpLfVHilQp2cHMg3l8T+IA"
Line 3,945 ⟶ 4,404:
MsgHash.base64decode(text) :
ZLib.Inflator().write(_).close().read().text.println();</
{{out}}
<pre>
|