Old lady swallowed a fly: Difference between revisions

Content added Content deleted
m (syntax highlighting fixup automation)
Line 13: Line 13:
{{trans|Python}}
{{trans|Python}}


<lang 11l>V animals = [
<syntaxhighlight lang="11l">V animals = [
(‘fly’, ‘I don't know why she swallowed a fly, perhaps she'll die.’),
(‘fly’, ‘I don't know why she swallowed a fly, perhaps she'll die.’),
(‘spider’, ‘It wiggled and jiggled and tickled inside her.’),
(‘spider’, ‘It wiggled and jiggled and tickled inside her.’),
Line 36: Line 36:
I animal != ‘fly’
I animal != ‘fly’
print(animals[0][1])
print(animals[0][1])
print()</lang>
print()</syntaxhighlight>


=={{header|8080 Assembly}}==
=={{header|8080 Assembly}}==
<lang 8080asm> org 100h
<syntaxhighlight lang="8080asm"> org 100h
mvi c,-1 ; C = verse counter
mvi c,-1 ; C = verse counter
verse: inr c
verse: inr c
Line 110: Line 110:
swlw1: db 'She swallowed the $'
swlw1: db 'She swallowed the $'
swlw2: db ' to catch the $'
swlw2: db ' to catch the $'
comma: db ',',13,10,'$'</lang>
comma: db ',',13,10,'$'</syntaxhighlight>


=={{header|8086 Assembly}}==
=={{header|8086 Assembly}}==
<lang asm> cpu 8086
<syntaxhighlight lang="asm"> cpu 8086
org 100h
org 100h
section .text
section .text
Line 177: Line 177:
swlw1: db 'She swallowed the $'
swlw1: db 'She swallowed the $'
swlw2: db ' to catch the $'
swlw2: db ' to catch the $'
comma: db ',',13,10,'$'</lang>
comma: db ',',13,10,'$'</syntaxhighlight>


=={{header|Ada}}==
=={{header|Ada}}==
<lang Ada>with Ada.Text_IO, Ada.Containers.Indefinite_Doubly_Linked_Lists; use Ada.Text_IO;
<syntaxhighlight lang="ada">with Ada.Text_IO, Ada.Containers.Indefinite_Doubly_Linked_Lists; use Ada.Text_IO;


procedure Swallow_Fly is
procedure Swallow_Fly is
Line 237: Line 237:
Put_Line("There was an old lady who swallowed a horse ...");
Put_Line("There was an old lady who swallowed a horse ...");
Put_Line("She's dead, of course!");
Put_Line("She's dead, of course!");
end Swallow_Fly;</lang>
end Swallow_Fly;</syntaxhighlight>


=={{header|ALGOL 68}}==
=={{header|ALGOL 68}}==
Line 244: 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].}}
{{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''.}}
{{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''.}}
<lang algol68>#!/usr/local/bin/a68g --script #
<syntaxhighlight lang="algol68">#!/usr/local/bin/a68g --script #


STRING sw=" swallow ",swd=sw[:UPB sw-1]+"ed ", tsa=". To"+sw+"a";
STRING sw=" swallow ",swd=sw[:UPB sw-1]+"ed ", tsa=". To"+sw+"a";
Line 277: Line 277:
vs("Cow",("I don't know how",tsa));
vs("Cow",("I don't know how",tsa));
vs("Donkey",("It was rather wonky",tsa));
vs("Donkey",("It was rather wonky",tsa));
vs("Horse","She's dead, of course!")</lang>
vs("Horse","She's dead, of course!")</syntaxhighlight>


===Using a dictionary===
===Using a dictionary===
Line 283: 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].}}
{{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''.}}
{{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''.}}
<lang algol68>#!/usr/local/bin/a68g --script #
<syntaxhighlight lang="algol68">#!/usr/local/bin/a68g --script #


STRING a="WBXAY",b="WCXBY",c="WDXCY",d="WEXDY",
STRING a="WBXAY",b="WCXBY",c="WDXCY",d="WEXDY",
Line 321: Line 321:
OD;
OD;
print(new line)
print(new line)
OD</lang>
OD</syntaxhighlight>


=={{header|APL}}==
=={{header|APL}}==
{{works with|Dyalog APL}}
{{works with|Dyalog APL}}
<lang APL>oldLady←{
<syntaxhighlight lang="apl">oldLady←{
N←⎕TC[3]
N←⎕TC[3]
a←'fly' 'spider' 'bird' 'cat' 'dog' 'goat' 'cow' 'horse'
a←'fly' 'spider' 'bird' 'cat' 'dog' 'goat' 'cow' 'horse'
Line 344: Line 344:
}¨⌽1↓⍳⍵
}¨⌽1↓⍳⍵
}¨⍳8
}¨⍳8
}</lang>
}</syntaxhighlight>


=={{header|ARM Assembly}}==
=={{header|ARM Assembly}}==
<lang>.global _start
<syntaxhighlight lang="text">.global _start
_start: eor r8,r8,r8 @ Verse counter
_start: eor r8,r8,r8 @ Verse counter
verse: add r8,r8,#1 @ Next verse
verse: add r8,r8,#1 @ Next verse
Line 414: Line 414:
swa1: .asciz "She swallowed the "
swa1: .asciz "She swallowed the "
swa2: .asciz " to catch the "
swa2: .asciz " to catch the "
comma: .asciz ",\n" </lang>
comma: .asciz ",\n" </syntaxhighlight>


=={{header|AutoHotkey}}==
=={{header|AutoHotkey}}==
{{works with|AutoHotkey 1.1}}
{{works with|AutoHotkey 1.1}}
<lang AutoHotkey>Animals := [["fly", "I don't know why she swallowed the "]
<syntaxhighlight lang="autohotkey">Animals := [["fly", "I don't know why she swallowed the "]
, ["spider", "That wriggled and jiggled and tickled inside her"]
, ["spider", "That wriggled and jiggled and tickled inside her"]
, ["bird", "Quite absurd"]
, ["bird", "Quite absurd"]
Line 436: Line 436:
}
}


MsgBox, % Output</lang>
MsgBox, % Output</syntaxhighlight>


=={{header|AWK}}==
=={{header|AWK}}==
<syntaxhighlight lang="awk">
<lang AWK>
# syntax: GAWK -f OLD_LADY_SWALLOWED_A_FLY.AWK
# syntax: GAWK -f OLD_LADY_SWALLOWED_A_FLY.AWK
BEGIN {
BEGIN {
Line 473: Line 473:
exit(0)
exit(0)
}
}
</syntaxhighlight>
</lang>


=={{header|Babel}}==
=={{header|Babel}}==
<lang babel>((main {fly !})
<syntaxhighlight lang="babel">((main {fly !})


(fly
(fly
Line 520: Line 520:
("spider" "That wriggled and jiggled and tickled inside her")
("spider" "That wriggled and jiggled and tickled inside her")
("fly" " "))))
("fly" " "))))
</syntaxhighlight>
</lang>


=={{header|Batch File}}==
=={{header|Batch File}}==
<lang dos>@echo off
<syntaxhighlight lang="dos">@echo off
setlocal enabledelayedexpansion
setlocal enabledelayedexpansion


Line 568: Line 568:
)
)
:done
:done
pause>nul&exit/b 0</lang>
pause>nul&exit/b 0</syntaxhighlight>


=={{header|BBC BASIC}}==
=={{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.
This prints the lyrics from the Wikipedia page, more or less. I don't know anything about goats and donkeys and the like.
<lang bbcbasic>REM >oldlady
<syntaxhighlight lang="bbcbasic">REM >oldlady
DIM swallowings$(6, 1)
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"
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: Line 599:
PRINT observation$; "!"
PRINT observation$; "!"
ENDCASE
ENDCASE
ENDPROC</lang>
ENDPROC</syntaxhighlight>


=={{header|BCPL}}==
=={{header|BCPL}}==
<lang bcpl>get "libhdr"
<syntaxhighlight lang="bcpl">get "libhdr"


let animal(n) =
let animal(n) =
Line 631: Line 631:
$)
$)


let start() be for n=0 to 7 do verse(n)</lang>
let start() be for n=0 to 7 do verse(n)</syntaxhighlight>


=={{header|Befunge}}==
=={{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.
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.


<lang befunge>055*46*146*1->00p 36268>5\:4\:2v >\#%"O"/#:3#:+#< g48*- >1-:!#v_\1+::"O"%\"O"/v
<syntaxhighlight lang="befunge">055*46*146*1->00p 36268>5\:4\:2v >\#%"O"/#:3#:+#< g48*- >1-:!#v_\1+::"O"%\"O"/v
>-#2:#\8#1`#:|#-1:-1\7_^#`g00:+<>\#%"O"/#::$#<3#$+g48*-v^\,+*+ 55!:*!!-"|":g+3<
>-#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_@#:>#<$<
>$ 36 26 58 49 81 36 26 10 \1-:#^\_^#:-1\+<00_@#:>#<$<
Line 644: Line 644:
.|Fancy that$Dog-.|What a hog$Pig7.|Her mouth was so big%Goat=.|She just opened
.|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
her throat$Cow3.|I don't know how'Donkey6.|It was rather wonky&Horse:.|She's d
ead, of course!|</lang>
ead, of course!|</syntaxhighlight>


=={{header|C}}==
=={{header|C}}==
<lang c>#include <stdio.h>
<syntaxhighlight lang="c">#include <stdio.h>
static char const *animals[] = {
static char const *animals[] = {
"fly",
"fly",
Line 682: Line 682:
}
}
}
}
}</lang>
}</syntaxhighlight>


=={{header|C sharp|C#}}==
=={{header|C sharp|C#}}==
<lang csharp>using System;
<syntaxhighlight lang="csharp">using System;


namespace OldLady
namespace OldLady
Line 725: Line 725:
}
}
}
}
}</lang>
}</syntaxhighlight>


=={{header|C++}}==
=={{header|C++}}==
{{trans|C#}}
{{trans|C#}}
<lang cpp>#include <iostream>
<syntaxhighlight lang="cpp">#include <iostream>


const char *CREATURES[] = { "fly", "spider", "bird", "cat", "dog", "goat", "cow", "horse" };
const char *CREATURES[] = { "fly", "spider", "bird", "cat", "dog", "goat", "cow", "horse" };
Line 756: Line 756:


return 0;
return 0;
}</lang>
}</syntaxhighlight>
{{out}}
{{out}}
<pre>There was an old lady who swallowed a fly
<pre>There was an old lady who swallowed a fly
Line 817: Line 817:


=={{header|CLU}}==
=={{header|CLU}}==
<lang clu>old_lady = cluster is swallow
<syntaxhighlight lang="clu">old_lady = cluster is swallow
rep = null
rep = null
Line 857: Line 857:
start_up = proc ()
start_up = proc ()
old_lady$swallow(stream$primary_output())
old_lady$swallow(stream$primary_output())
end start_up</lang>
end start_up</syntaxhighlight>


=={{header|COBOL}}==
=={{header|COBOL}}==
<lang cobol> IDENTIFICATION DIVISION.
<syntaxhighlight lang="cobol"> IDENTIFICATION DIVISION.
PROGRAM-ID. OLD-LADY.
PROGRAM-ID. OLD-LADY.


Line 950: Line 950:
DISPLAY LINE-OUT.
DISPLAY LINE-OUT.
</syntaxhighlight>
</lang>


=={{header|Commodore BASIC}}==
=={{header|Commodore BASIC}}==
Line 958: Line 958:


===Commodore BASIC (No Sound)===
===Commodore BASIC (No Sound)===
<lang gwbasic>
<syntaxhighlight lang="gwbasic">
1 rem rosetta code
1 rem rosetta code
2 rem old lady who swallowed a fly
2 rem old lady who swallowed a fly
Line 992: Line 992:
1070 data "cow","I don't know how she swallowed a cow!"
1070 data "cow","I don't know how she swallowed a cow!"
1080 data "horse","...She died, of course!"
1080 data "horse","...She died, of course!"
</syntaxhighlight>
</lang>


===Commodore 64===
===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.
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.
<lang gwbasic>
<syntaxhighlight lang="gwbasic">
1 rem rosetta code
1 rem rosetta code
2 rem old lady who swallowed a fly - c64
2 rem old lady who swallowed a fly - c64
Line 1,063: Line 1,063:
2550 for i=1 to 8:for j=1 to 3:read mu$(i,j):next j:next i
2550 for i=1 to 8:for j=1 to 3:read mu$(i,j):next j:next i
2599 return
2599 return
</syntaxhighlight>
</lang>


===Commodore Plus/4===
===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.
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.
<lang gwbasic>
<syntaxhighlight lang="gwbasic">
1 rem rosetta code
1 rem rosetta code
2 rem old lady who swallowed a fly - plus/4
2 rem old lady who swallowed a fly - plus/4
Line 1,135: Line 1,135:
2550 for i=1 to 8:for j=1 to 3:read mu$(i,j):next j:next i
2550 for i=1 to 8:for j=1 to 3:read mu$(i,j):next j:next i
2599 return
2599 return
</syntaxhighlight>
</lang>


===Commodore 128===
===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.
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.
<lang gwbasic>
<syntaxhighlight lang="gwbasic">
1 rem rosetta code
1 rem rosetta code
2 rem old lady who swallowed a fly - c128
2 rem old lady who swallowed a fly - c128
Line 1,191: Line 1,191:
2520 play "v1o4t0u5"
2520 play "v1o4t0u5"
2599 return
2599 return
</syntaxhighlight>
</lang>


=={{header|Common Lisp}}==
=={{header|Common Lisp}}==
A rather iterative, rather than recursive solution. The lyrics match the original Burl Ives recording (not the later animated cartoon):
A rather iterative, rather than recursive solution. The lyrics match the original Burl Ives recording (not the later animated cartoon):


<lang lisp>(defun verse (what remark &optional always die) (list what remark always die))
<syntaxhighlight lang="lisp">(defun verse (what remark &optional always die) (list what remark always die))
(defun what (verse) (first verse))
(defun what (verse) (first verse))
(defun remark (verse) (second verse))
(defun remark (verse) (second verse))
Line 1,232: Line 1,232:
(if (always v)
(if (always v)
(format t "~a~a~%" (if (= j 0) "But " "") (remark v))))))
(format t "~a~a~%" (if (= j 0) "But " "") (remark v))))))
(format t "Perhaps she'll die. ~%~%"))))))</lang>
(format t "Perhaps she'll die. ~%~%"))))))</syntaxhighlight>


{{Out}}
{{Out}}
Line 1,263: Line 1,263:


=={{header|Cowgol}}==
=={{header|Cowgol}}==
<lang cowgol>include "cowgol.coh";
<syntaxhighlight lang="cowgol">include "cowgol.coh";


var animals: [uint8][] := {
var animals: [uint8][] := {
Line 1,303: Line 1,303:
i := i + 1;
i := i + 1;
end loop;</lang>
end loop;</syntaxhighlight>


=={{header|D}}==
=={{header|D}}==
{{trans|C}}
{{trans|C}}
<lang d>import core.stdc.stdio;
<syntaxhighlight lang="d">import core.stdc.stdio;


immutable data = [
immutable data = [
Line 1,335: Line 1,335:
void main() {
void main() {
data[0].oldLady;
data[0].oldLady;
}</lang>
}</syntaxhighlight>


A more structured alternative version:
A more structured alternative version:
<lang d>enum Action { once, every, die }
<syntaxhighlight lang="d">enum Action { once, every, die }


immutable struct T {
immutable struct T {
Line 1,378: Line 1,378:
"Perhaps she'll die.\n".writeln;
"Perhaps she'll die.\n".writeln;
}
}
}</lang>
}</syntaxhighlight>


=={{header|Draco}}==
=={{header|Draco}}==
<lang draco>proc nonrec animal(byte n) *char:
<syntaxhighlight lang="draco">proc nonrec animal(byte n) *char:
case n
case n
incase 0: "fly"
incase 0: "fly"
Line 1,425: Line 1,425:
byte n;
byte n;
for n from 0 upto 7 do verse(n) od
for n from 0 upto 7 do verse(n) od
corp</lang>
corp</syntaxhighlight>


=={{header|Elena}}==
=={{header|Elena}}==
ELENA 5.0 :
ELENA 5.0 :
<lang elena>import extensions;
<syntaxhighlight lang="elena">import extensions;
const Creatures = new string[]{"fly", "spider", "bird", "cat", "dog", "goat", "cow", "horse"};
const Creatures = new string[]{"fly", "spider", "bird", "cat", "dog", "goat", "cow", "horse"};
Line 1,464: Line 1,464:
console.writeLine()
console.writeLine()
}
}
}</lang>
}</syntaxhighlight>


=={{header|Elixir}}==
=={{header|Elixir}}==
{{trans|Ruby}}
{{trans|Ruby}}
<lang elixir>defmodule Old_lady do
<syntaxhighlight lang="elixir">defmodule Old_lady do
@descriptions [
@descriptions [
fly: "I don't know why S",
fly: "I don't know why S",
Line 1,515: Line 1,515:
end
end


Old_lady.swallowed</lang>
Old_lady.swallowed</syntaxhighlight>


=={{header|Factor}}==
=={{header|Factor}}==
Windows users should put zlib1.dll[http://downloads.factorcode.org/dlls/] to factor folder.
Windows users should put zlib1.dll[http://downloads.factorcode.org/dlls/] to factor folder.
<lang factor>USING: base85 compression.zlib ;
<syntaxhighlight lang="factor">USING: base85 compression.zlib ;


"c%1E4%WlIU5WMphn^P`UexSD=s^-?Jk$NVE7-Gs=fQ9_`T}Y~ggi4hvMSb{SX}vpQXJ;^Yqok7%xd(0
"c%1E4%WlIU5WMphn^P`UexSD=s^-?Jk$NVE7-Gs=fQ9_`T}Y~ggi4hvMSb{SX}vpQXJ;^Yqok7%xd(0
Line 1,528: Line 1,528:
<}rUt#FCDtKB9S`Y4jg+0PuB?Qt-&(11p?caq^S=1C`$D1fa<y6|YD*77a{4949T_-MVet;6abaEn"
<}rUt#FCDtKB9S`Y4jg+0PuB?Qt-&(11p?caq^S=1C`$D1fa<y6|YD*77a{4949T_-MVet;6abaEn"


base85> 3215 <compressed> uncompress >string print</lang>
base85> 3215 <compressed> uncompress >string print</syntaxhighlight>


=={{header|Forth}}==
=={{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.
swallow-addr is obviously a good candidate for an object, but Forth has many OO candidates - we won't settle that argument here.
<lang forth>: string, ( c-addr u -- ) \ store string at HERE , with a count
<syntaxhighlight lang="forth">: string, ( c-addr u -- ) \ store string at HERE , with a count
dup c, here swap dup allot move ;
dup c, here swap dup allot move ;


Line 1,585: Line 1,585:
first @ begin dup verse cr >next dup 0= until drop
first @ begin dup verse cr >next dup 0= until drop
cr ." There was an old lady who swallowed a horse..."
cr ." There was an old lady who swallowed a horse..."
cr ." She's dead, of course!" ;</lang>
cr ." She's dead, of course!" ;</syntaxhighlight>


=={{header|Fortran}}==
=={{header|Fortran}}==
<syntaxhighlight lang="fortran">
<lang Fortran>
program fly
program fly
!A program to print the "Old lady swallowed a fly" poem
!A program to print the "Old lady swallowed a fly" poem
Line 1,627: Line 1,627:
end program fly
end program fly
</syntaxhighlight>
</lang>


=={{header|FreeBASIC}}==
=={{header|FreeBASIC}}==
<lang freebasic>dim as string lyrics(0 to 7, 0 to 1) = {_
<syntaxhighlight lang="freebasic">dim as string lyrics(0 to 7, 0 to 1) = {_
{ "fly", "I don't know why she swallowed a fly - Perhaps she'll die!" },_
{ "fly", "I don't know why she swallowed a fly - Perhaps she'll die!" },_
{ "spider", "That wriggled and jiggled and tickled inside her!" },_
{ "spider", "That wriggled and jiggled and tickled inside her!" },_
Line 1,652: Line 1,652:
next countdown
next countdown
print
print
next verse</lang>
next verse</syntaxhighlight>


=={{header|Free Pascal}}==
=={{header|Free Pascal}}==
<lang Free Pascal>(* A mixture of the lyrics found in Wikipedia and the Ada version
<syntaxhighlight lang="free pascal">(* A mixture of the lyrics found in Wikipedia and the Ada version
in Rosetta Code. It formats the lyrics like the Wikipedia one *)
in Rosetta Code. It formats the lyrics like the Wikipedia one *)
program OldLady;
program OldLady;
Line 1,735: Line 1,735:
PrintSong;
PrintSong;
end.
end.
</syntaxhighlight>
</lang>


=={{header|Frege}}==
=={{header|Frege}}==
Line 1,743: Line 1,743:
Nearly identical to the Haskell. Only the first line of the program is different.
Nearly identical to the Haskell. Only the first line of the program is different.


<lang frege>module OldLady where
<syntaxhighlight lang="frege">module OldLady where


import Data.List
import Data.List
Line 1,783: Line 1,783:
song = concatMap verse $ tail $ reverse $ tails animals
song = concatMap verse $ tail $ reverse $ tails animals


main = putStr $ unlines song</lang>
main = putStr $ unlines song</syntaxhighlight>


=={{header|Go}}==
=={{header|Go}}==
[https://play.golang.org/p/OV3YJSWxaJP Go Playground]
[https://play.golang.org/p/OV3YJSWxaJP Go Playground]
<lang go>package main
<syntaxhighlight lang="go">package main


import "fmt"
import "fmt"
Line 1,824: Line 1,824:
fmt.Println(animals[0][lyric] + "\n")
fmt.Println(animals[0][lyric] + "\n")
}
}
}</lang>
}</syntaxhighlight>


=={{header|Haskell}}==
=={{header|Haskell}}==


<lang haskell>import Data.List (tails)
<syntaxhighlight lang="haskell">import Data.List (tails)


animals :: [String]
animals :: [String]
Line 1,856: Line 1,856:
putStr $
putStr $
concatMap unlines $
concatMap unlines $
zipWith (:) beginnings $ reverse $ ([] :) (tails lastVerse)</lang>
zipWith (:) beginnings $ reverse $ ([] :) (tails lastVerse)</syntaxhighlight>
{{out}}<pre>There was an old lady who swallowed a fly.
{{out}}<pre>There was an old lady who swallowed a fly.
I don't know why she swallowed a fly.
I don't know why she swallowed a fly.
Line 1,923: Line 1,923:
And a variation on this theme (a little more disaggregated):
And a variation on this theme (a little more disaggregated):


<lang haskell>import Prelude hiding (lookup)
<syntaxhighlight lang="haskell">import Prelude hiding (lookup)
import Data.Map.Strict (Map, fromList, lookup)
import Data.Map.Strict (Map, fromList, lookup)
import Data.List (inits, intercalate)
import Data.List (inits, intercalate)
Line 1,984: Line 1,984:


comments :: Map String String
comments :: Map String String
comments = fromList courses</lang>
comments = fromList courses</syntaxhighlight>
{{Out}}
{{Out}}
<pre>There was an old lady who swallowed a fly;
<pre>There was an old lady who swallowed a fly;
Line 2,050: Line 2,050:
=={{header|Icon}} and {{header|Unicon}}==
=={{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.
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.
<lang Icon>procedure main() #: There Was An Old Lady Lyrics
<syntaxhighlight lang="icon">procedure main() #: There Was An Old Lady Lyrics


verse := table() # arglists for printf - [1] long asides and [2] terse joiners
verse := table() # arglists for printf - [1] long asides and [2] terse joiners
Line 2,081: Line 2,081:
end
end


link printf</lang>
link printf</syntaxhighlight>
Sample output omitted.
Sample output omitted.


Line 2,089: Line 2,089:
=={{header|J}}==
=={{header|J}}==
This defines T to be the required text.
This defines T to be the required text.
<lang j>T=:''
<syntaxhighlight lang="j">T=:''
e=:3 :'T=:T,y,LF'
e=:3 :'T=:T,y,LF'
E=:e@,&'.'
E=:e@,&'.'
Line 2,112: Line 2,112:
'Donkey'N'It was rather wonky'
'Donkey'N'It was rather wonky'
O'Horse'
O'Horse'
e'She''s dead, of course!'</lang>
e'She''s dead, of course!'</syntaxhighlight>


=={{header|Java}}==
=={{header|Java}}==
{{Trans|C| via [[#D|D]]}}
{{Trans|C| via [[#D|D]]}}
<lang java>public class OldLadySwallowedAFly {
<syntaxhighlight lang="java">public class OldLadySwallowedAFly {


final static String[] data = {
final static String[] data = {
Line 2,144: Line 2,144:
oldLady(data[0], false);
oldLady(data[0], false);
}
}
}</lang>
}</syntaxhighlight>


=={{header|Julia}}==
=={{header|Julia}}==
{{works with|Julia|0.6}}
{{works with|Julia|0.6}}


<lang julia>using CodecZlib
<syntaxhighlight lang="julia">using CodecZlib


b64 = b"""eNrtVE1rwzAMvedXaKdeRn7ENrb21rHCzmrs1m49K9gOJv9+cko/HBcGg0LHcpOfnq2np0QL
b64 = b"""eNrtVE1rwzAMvedXaKdeRn7ENrb21rHCzmrs1m49K9gOJv9+cko/HBcGg0LHcpOfnq2np0QL
Line 2,158: Line 2,158:
Mz3XkPBc/TSN3yxGiqMiipHRekycK0ZwMhM8jerGC9zuZaoTho3kMKSfJjLaF8v8wLzmXMqM
Mz3XkPBc/TSN3yxGiqMiipHRekycK0ZwMhM8jerGC9zuZaoTho3kMKSfJjLaF8v8wLzmXMqM
zJvGew/jnZPzclA08yAkikegDTTUMfzwDXBcwoE="""
zJvGew/jnZPzclA08yAkikegDTTUMfzwDXBcwoE="""
println(String(transcode(ZlibDecompressor(), base64decode(b64))))</lang>
println(String(transcode(ZlibDecompressor(), base64decode(b64))))</syntaxhighlight>


<lang julia>animals = [
<syntaxhighlight lang="julia">animals = [
("fly", "I don't know why she swallowed a fly, perhaps she'll die."),
("fly", "I don't know why she swallowed a fly, perhaps she'll die."),
("spider", "It wiggled and jiggled and tickled inside her."),
("spider", "It wiggled and jiggled and tickled inside her."),
Line 2,181: Line 2,181:
if animal != "fly" println(animals[1][2]) end # fly lyric
if animal != "fly" println(animals[1][2]) end # fly lyric
println() # new line
println() # new line
end</lang>
end</syntaxhighlight>


=={{header|Kotlin}}==
=={{header|Kotlin}}==
<lang scala>// version 1.1.3
<syntaxhighlight lang="scala">// version 1.1.3


val animals = listOf("fly", "spider", "bird", "cat","dog", "goat", "cow", "horse")
val animals = listOf("fly", "spider", "bird", "cat","dog", "goat", "cow", "horse")
Line 2,218: Line 2,218:
fun main(args: Array<String>) {
fun main(args: Array<String>) {
sing()
sing()
}</lang>
}</syntaxhighlight>


=={{header|Lambdatalk}}==
=={{header|Lambdatalk}}==
<lang scheme>
<syntaxhighlight lang="scheme">
{def A {A.new fly spider bird cat dog goat cow horse}}
{def A {A.new fly spider bird cat dog goat cow horse}}
-> A
-> A
Line 2,295: Line 2,295:
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
</syntaxhighlight>
</lang>


=={{header|Liberty BASIC}}==
=={{header|Liberty BASIC}}==
<syntaxhighlight lang="lb">
<lang lb>
'[RC] Old lady swallowed a fly
'[RC] Old lady swallowed a fly
'http://rosettacode.org/wiki/Old_lady_swallowed_a_fly
'http://rosettacode.org/wiki/Old_lady_swallowed_a_fly
Line 2,344: Line 2,344:


end
end
</syntaxhighlight>
</lang>


=={{header|Logo}}==
=={{header|Logo}}==
<lang logo>make "data [
<syntaxhighlight lang="logo">make "data [
; animal inc comment
; animal inc comment
[fly 2 [I don't know why she swallowed that fly]]
[fly 2 [I don't know why she swallowed that fly]]
Line 2,381: Line 2,381:
]
]


bye</lang>
bye</syntaxhighlight>


=={{header|Lua}}==
=={{header|Lua}}==
<lang lua>animals = {"fly", "spider", "bird", "cat","dog", "goat", "cow", "horse"}
<syntaxhighlight lang="lua">animals = {"fly", "spider", "bird", "cat","dog", "goat", "cow", "horse"}
phrases = {
phrases = {
"",
"",
Line 2,413: Line 2,413:
end
end
io.write("I don't know why she swallowed a fly - Perhaps she'll die!\n\n")
io.write("I don't know why she swallowed a fly - Perhaps she'll die!\n\n")
end</lang>
end</syntaxhighlight>


=={{header|MAD}}==
=={{header|MAD}}==
<lang MAD> NORMAL MODE IS INTEGER
<syntaxhighlight lang="mad"> NORMAL MODE IS INTEGER
INTERNAL FUNCTION(V)
INTERNAL FUNCTION(V)
Line 2,458: Line 2,458:
VERSE WHENEVER J.LE.2, VERSE.(J-1)
VERSE WHENEVER J.LE.2, VERSE.(J-1)
END OF PROGRAM </lang>
END OF PROGRAM </syntaxhighlight>


=={{header|Maple}}==
=={{header|Maple}}==
<lang maple>swallowed := ["fly", "spider", "bird", "cat", "dog", "cow", "horse"]:
<syntaxhighlight lang="maple">swallowed := ["fly", "spider", "bird", "cat", "dog", "cow", "horse"]:
phrases := ["I don't know why she swallowed a fly, perhaps she'll die!",
phrases := ["I don't know why she swallowed a fly, perhaps she'll die!",
"That wriggled and wiggled and tiggled inside her.",
"That wriggled and wiggled and tiggled inside her.",
Line 2,479: Line 2,479:
printf("\n");
printf("\n");
end if;
end if;
end do;</lang>
end do;</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 2,525: Line 2,525:


=={{header|Mathematica}}/{{header|Wolfram Language}}==
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<lang Mathematica>animals = {"fly", "spider", "bird", "cat", "dog", "goat", "cow",
<syntaxhighlight lang="mathematica">animals = {"fly", "spider", "bird", "cat", "dog", "goat", "cow",
"horse"};
"horse"};
notes = {"", "That wiggled and jiggled and tickled inside her.\n",
notes = {"", "That wiggled and jiggled and tickled inside her.\n",
Line 2,541: Line 2,541:
StringJoin @@ ("She swallowed the " <> animals[[#]] <>
StringJoin @@ ("She swallowed the " <> animals[[#]] <>
" to catch the " <> animals[[# - 1]] <> ".\n" & /@
" to catch the " <> animals[[# - 1]] <> ".\n" & /@
Range[#, 2, -1]) <> notes[[9]]] & /@ Range[8])];</lang>
Range[#, 2, -1]) <> notes[[9]]] & /@ Range[8])];</syntaxhighlight>
{{out}}
{{out}}
<pre>There was an old lady who swallowed a fly.
<pre>There was an old lady who swallowed a fly.
Line 2,602: Line 2,602:


=={{header|Mercury}}==
=={{header|Mercury}}==
<lang Mercury>:- module oldlady.
<syntaxhighlight lang="mercury">:- module oldlady.
:- interface.
:- interface.
:- import_module io.
:- import_module io.
Line 2,674: Line 2,674:


main(!IO) :-
main(!IO) :-
swallowed(fly, !IO).</lang>
swallowed(fly, !IO).</syntaxhighlight>


=={{header|Modula-2}}==
=={{header|Modula-2}}==
<lang modula2>MODULE OldLady;
<syntaxhighlight lang="modula2">MODULE OldLady;
FROM FormatString IMPORT FormatString;
FROM FormatString IMPORT FormatString;
FROM Terminal IMPORT WriteString,WriteLn,ReadChar;
FROM Terminal IMPORT WriteString,WriteLn,ReadChar;
Line 2,728: Line 2,728:


ReadChar
ReadChar
END OldLady.</lang>
END OldLady.</syntaxhighlight>


=={{header|Nanoquery}}==
=={{header|Nanoquery}}==
{{trans|Ursa}}
{{trans|Ursa}}
<lang nanoquery>reason = {"She swallowed the ", " to catch the "}
<syntaxhighlight lang="nanoquery">reason = {"She swallowed the ", " to catch the "}
creatures = {"fly", "spider", "bird", "cat", "dog", "goat", "cow", "horse"}
creatures = {"fly", "spider", "bird", "cat", "dog", "goat", "cow", "horse"}
comments = {"I don't know why she swallowed that fly.\nPerhaps she'll die\n",\
comments = {"I don't know why she swallowed that fly.\nPerhaps she'll die\n",\
Line 2,755: Line 2,755:
end
end


input()</lang>
input()</syntaxhighlight>


=={{header|Nim}}==
=={{header|Nim}}==
{{trans|Python}}
{{trans|Python}}
{{libheader|nim-lang/zip}}
{{libheader|nim-lang/zip}}
<lang nim>import zip/zlib, base64
<syntaxhighlight lang="nim">import zip/zlib, base64


const b64 = """
const b64 = """
Line 2,771: Line 2,771:
zJvGew/jnZPzclA08yAkikegDTTUMfzwDXBcwoE="""
zJvGew/jnZPzclA08yAkikegDTTUMfzwDXBcwoE="""


echo b64.decode.uncompress()</lang>
echo b64.decode.uncompress()</syntaxhighlight>


=={{header|OCaml}}==
=={{header|OCaml}}==
===Using a dictionary===
===Using a dictionary===
Only one minimalist line of code (the last line):
Only one minimalist line of code (the last line):
<lang ocaml>let d = [|
<syntaxhighlight lang="ocaml">let d = [|
"I know an old lady who swallowed a "; "fly"; ".\n";
"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";
"I don't know why she swallowed the fly.\nPerhaps she'll die.\n\n";
Line 2,807: Line 2,807:
[23] ;;
[23] ;;


List.iter (fun i -> print_string d.(i)) s</lang>
List.iter (fun i -> print_string d.(i)) s</syntaxhighlight>
===Using dictionary based decompression===
===Using dictionary based decompression===
{{trans|D}}
{{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]:
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]:
<lang ocaml>let dict = [|
<syntaxhighlight lang="ocaml">let dict = [|
"_ha _c _e _p,\nQuite absurd_f_p;_`cat,\nFancy that_fcat;_j`dog,\nWhat a hog_\
"_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\
fdog;_l`pig,\nHer mouth_qso big_fpig;_d_r,\nShe just opened her throat_f_r;_i\
Line 2,829: Line 2,829:
let _ =
let _ =
old_lady dict.(0) false</lang>
old_lady dict.(0) false</syntaxhighlight>
===Using Logic===
===Using Logic===
<lang ocaml>let an =
<syntaxhighlight lang="ocaml">let an =
[| "fly"; "spider"; "bird"; "cat"; "dog"; "pig"; "goat"; "cow"; "donkey" |]
[| "fly"; "spider"; "bird"; "cat"; "dog"; "pig"; "goat"; "cow"; "donkey" |]


Line 2,862: Line 2,862:
for i = 0 to 8 do f i done;
for i = 0 to 8 do f i done;
p "There was an old lady who swallowed a horse...\n\
p "There was an old lady who swallowed a horse...\n\
She's dead, of course!"</lang>
She's dead, of course!"</syntaxhighlight>


=={{header|Perl}}==
=={{header|Perl}}==
Using string subst:<lang perl>my @animals = (
Using string subst:<syntaxhighlight lang="perl">my @animals = (
"fly",
"fly",
"spider/That wriggled and jiggled and tickled inside her.\n",
"spider/That wriggled and jiggled and tickled inside her.\n",
Line 2,896: Line 2,896:
s/:.*/--\nShe's dead, of course!\n/s;
s/:.*/--\nShe's dead, of course!\n/s;
print;
print;
}</lang>
}</syntaxhighlight>
Using compression:
Using compression:
(Assumes a Unix-like OS and the availability of the uudecode and bunzip2 utilities).
(Assumes a Unix-like OS and the availability of the uudecode and bunzip2 utilities).
<lang perl>open OUT, "| uudecode | bunzip2" and
<syntaxhighlight lang="perl">open OUT, "| uudecode | bunzip2" and
print OUT <DATA> and
print OUT <DATA> and
close OUT;
close OUT;
Line 2,916: Line 2,916:
FeXUOI8486Wvor1zajqPDfpwnrn2jOzvo8hkOPrpVajlwnjqPfIry5c0TbKL
FeXUOI8486Wvor1zajqPDfpwnrn2jOzvo8hkOPrpVajlwnjqPfIry5c0TbKL
559fx8xqpsquRaFYV9I9fT6p7RrI/Gv/F3JFOFCQRJtf/Q==
559fx8xqpsquRaFYV9I9fT6p7RrI/Gv/F3JFOFCQRJtf/Q==
====</lang>
====</syntaxhighlight>


=={{header|Phix}}==
=={{header|Phix}}==
{{Trans|Ada}}
{{Trans|Ada}}
<!--<lang Phix>(phixonline)-->
<!--<syntaxhighlight lang="phix">(phixonline)-->
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<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: #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>
Line 2,949: Line 2,949:
<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: #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>
<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>
<!--</lang>-->
<!--</syntaxhighlight>-->


=={{header|PHP}}==
=={{header|PHP}}==
<lang php><?php
<syntaxhighlight lang="php"><?php


$swallowed = array(
$swallowed = array(
Line 2,991: Line 2,991:
else
else
print "Perhaps she'll die." . "\n\n";
print "Perhaps she'll die." . "\n\n";
}</lang>
}</syntaxhighlight>


=={{header|PicoLisp}}==
=={{header|PicoLisp}}==
{{trans|C}}
{{trans|C}}
<lang PicoLisp>(de *Dict
<syntaxhighlight lang="picolisp">(de *Dict
`(chop
`(chop
"_ha _c _e _p,/Quite absurd_f_p;_`cat,/Fancy that_fcat;_j`dog,\
"_ha _c _e _p,/Quite absurd_f_p;_`cat,/Fancy that_fcat;_j`dog,\
Line 3,036: Line 3,036:
Flg )
Flg )


(oldLady (car *Dict))</lang>
(oldLady (car *Dict))</syntaxhighlight>


=={{header|PL/M}}==
=={{header|PL/M}}==
<lang plm>100H:
<syntaxhighlight lang="plm">100H:


/* CP/M CALL */
/* CP/M CALL */
Line 3,101: Line 3,101:


CALL BDOS(0,0);
CALL BDOS(0,0);
EOF</lang>
EOF</syntaxhighlight>


=={{header|PowerShell}}==
=={{header|PowerShell}}==
<lang powershell>
<syntaxhighlight lang="powershell">
$lines = @(
$lines = @(
'fly/'
'fly/'
Line 3,136: Line 3,136:
"Perhaps she'll die."
"Perhaps she'll die."
""
""
}</lang>
}</syntaxhighlight>


=={{header|Python}}==
=={{header|Python}}==
<lang python>import zlib, base64
<syntaxhighlight lang="python">import zlib, base64


b64 = b'''
b64 = b'''
Line 3,149: Line 3,149:
Mz3XkPBc/TSN3yxGiqMiipHRekycK0ZwMhM8jerGC9zuZaoTho3kMKSfJjLaF8v8wLzmXMqM
Mz3XkPBc/TSN3yxGiqMiipHRekycK0ZwMhM8jerGC9zuZaoTho3kMKSfJjLaF8v8wLzmXMqM
zJvGew/jnZPzclA08yAkikegDTTUMfzwDXBcwoE='''
zJvGew/jnZPzclA08yAkikegDTTUMfzwDXBcwoE='''
print(zlib.decompress(base64.b64decode(b64)).decode("utf-8", "strict"))</lang>
print(zlib.decompress(base64.b64decode(b64)).decode("utf-8", "strict"))</syntaxhighlight>


<lang python>animals = [
<syntaxhighlight lang="python">animals = [
("fly", "I don't know why she swallowed a fly, perhaps she'll die."),
("fly", "I don't know why she swallowed a fly, perhaps she'll die."),
("spider", "It wiggled and jiggled and tickled inside her."),
("spider", "It wiggled and jiggled and tickled inside her."),
Line 3,170: Line 3,170:


if animal != "fly": print(animals[0][1]) # fly lyric
if animal != "fly": print(animals[0][1]) # fly lyric
print() # new line</lang>
print() # new line</syntaxhighlight>


=={{header|R}}==
=={{header|R}}==
<lang R>animals = list(
<syntaxhighlight lang="r">animals = list(
c("fly", "I don't know why she swallowed a fly, perhaps she'll die."),
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."),
c("spider", "It wiggled and jiggled and tickled inside her."),
Line 3,205: Line 3,205:
oldladysnack <- oldladysnack + 1
oldladysnack <- oldladysnack + 1
}
}
</syntaxhighlight>
</lang>


=={{header|Racket}}==
=={{header|Racket}}==
<lang racket>
<syntaxhighlight lang="racket">
#lang at-exp racket
#lang at-exp racket


Line 3,233: Line 3,233:
@line{}
@line{}
(loop more (cons animal seen)))])))
(loop more (cons animal seen)))])))
</syntaxhighlight>
</lang>
Alternative solution:
Alternative solution:
<lang racket>
<syntaxhighlight lang="racket">
#lang s-exp framework/private/decode
#lang s-exp framework/private/decode
7VK7TsQwEOz9FcM1AcncZyCoQaLey/piCyuObJ+s/D3rXHj4lIIKgaCItJkZ7cyOfM0uTZ5m
7VK7TsQwEOz9FcM1AcncZyCoQaLey/piCyuObJ+s/D3rXHj4lIIKgaCItJkZ7cyOfM0uTZ5m
Line 3,242: Line 3,242:
U+SaYuVXditxxdu8b338rOvEUas7GvuVa44Tcuu2/qz7CHuu6PeWwGHQ6rmiBCtz24KwWy0I
U+SaYuVXditxxdu8b338rOvEUas7GvuVa44Tcuu2/qz7CHuu6PeWwGHQ6rmiBCtz24KwWy0I
3KZdqvwDbfWhXPhY+S59RLX5dkTapF66/2/3fYMNMZklVJfAhlgjHKW2k8B7tbtRrw==
3KZdqvwDbfWhXPhY+S59RLX5dkTapF66/2/3fYMNMZklVJfAhlgjHKW2k8B7tbtRrw==
</syntaxhighlight>
</lang>


=={{header|Raku}}==
=={{header|Raku}}==
(formerly Perl 6)
(formerly Perl 6)
<lang perl6>my @victims =
<syntaxhighlight lang="raku" line>my @victims =
fly => " I don't know why S—",
fly => " I don't know why S—",
spider => " That wriggled and jiggled and tickled inside her.",
spider => " That wriggled and jiggled and tickled inside her.",
Line 3,270: Line 3,270:
@history.unshift($_) if @history < 5;
@history.unshift($_) if @history < 5;
@history.unshift("X to catch the $victim,");
@history.unshift("X to catch the $victim,");
}</lang>
}</syntaxhighlight>
And that's how I larned it!
And that's how I larned it!


=={{header|REXX}}==
=={{header|REXX}}==
<lang rexx>/*REXX program displays song lyrics for: "I Know an Old Lady who Swallowed a Fly". */
<syntaxhighlight lang="rexx">/*REXX program displays song lyrics for: "I Know an Old Lady who Swallowed a Fly". */
sw= 79 /*the width of the terminal screen, -1.*/
sw= 79 /*the width of the terminal screen, -1.*/
@.=; @.1 = "I don't know why she swallowed a fly,"
@.=; @.1 = "I don't know why she swallowed a fly,"
Line 3,297: Line 3,297:
say center(@.1, sw)
say center(@.1, sw)
say center("I guess she'll die.", sw)
say center("I guess she'll die.", sw)
end /*j*/ /*stick a fork in it, we're all done. */</lang>
end /*j*/ /*stick a fork in it, we're all done. */</syntaxhighlight>
{{out|output|text=&nbsp; (with the lyrics being centered):}}
{{out|output|text=&nbsp; (with the lyrics being centered):}}
<pre>
<pre>
Line 3,365: Line 3,365:


=={{header|Ruby}}==
=={{header|Ruby}}==
<lang ruby>descriptions = {
<syntaxhighlight lang="ruby">descriptions = {
:fly => "I don't know why S",
:fly => "I don't know why S",
:spider => "That wriggled and jiggled and tickled inside her.",
:spider => "That wriggled and jiggled and tickled inside her.",
Line 3,396: Line 3,396:


print "Perhaps she'll die.\n\n"
print "Perhaps she'll die.\n\n"
end</lang>
end</syntaxhighlight>


=={{header|Rust}}==
=={{header|Rust}}==
[https://play.rust-lang.org/?gist=294c9e29f206d7c8d8028aa5e7002d9a&version=nightly Rust Playground]
[https://play.rust-lang.org/?gist=294c9e29f206d7c8d8028aa5e7002d9a&version=nightly Rust Playground]
<lang rust>enum Action {Once, Every, Die}
<syntaxhighlight lang="rust">enum Action {Once, Every, Die}
use Action::*;
use Action::*;


Line 3,431: Line 3,431:
println!("Perhaps she'll die.\n");
println!("Perhaps she'll die.\n");
}
}
}</lang>
}</syntaxhighlight>


=={{header|Scala}}==
=={{header|Scala}}==
<lang Scala>case class Verse(animal: String, remark: String, die: Boolean = false, always: Boolean = false)
<syntaxhighlight lang="scala">case class Verse(animal: String, remark: String, die: Boolean = false, always: Boolean = false)


val verses = List(
val verses = List(
Line 3,460: Line 3,460:
println
println
}
}
}</lang>
}</syntaxhighlight>
{{out}}
{{out}}
<pre>There was an old lady who swallowed a fly,
<pre>There was an old lady who swallowed a fly,
Line 3,489: Line 3,489:


=={{header|Seed7}}==
=={{header|Seed7}}==
<lang seed7>$ include "seed7_05.s7i";
<syntaxhighlight lang="seed7">$ include "seed7_05.s7i";


const array array string: verses is [] (
const array array string: verses is [] (
Line 3,522: Line 3,522:
end if;
end if;
end for;
end for;
end func;</lang>
end func;</syntaxhighlight>


=={{header|Sidef}}==
=={{header|Sidef}}==
{{trans|Raku}}
{{trans|Raku}}
<lang ruby>var victims = [
<syntaxhighlight lang="ruby">var victims = [
:fly: " I don't know why S—",
:fly: " I don't know why S—",
:spider: " That wriggled and jiggled and tickled inside her.",
:spider: " That wriggled and jiggled and tickled inside her.",
Line 3,553: Line 3,553:
history.len < 5 && history.unshift(verse);
history.len < 5 && history.unshift(verse);
history.unshift("X to catch the #{victim},");
history.unshift("X to catch the #{victim},");
};</lang>
};</syntaxhighlight>


=={{header|Tcl}}==
=={{header|Tcl}}==
Because the song is highly repetitive, it compresses wonderfully.
Because the song is highly repetitive, it compresses wonderfully.
<lang tcl>package require Tcl 8.6
<syntaxhighlight lang="tcl">package require Tcl 8.6


puts [zlib inflate [binary decode base64 "
puts [zlib inflate [binary decode base64 "
Line 3,568: Line 3,568:
nCtGcDITPI3qxgvc7mWqE4aN5DCknyYy2hfL/MC85lzKjMybxnsP452T83JQNPMg
nCtGcDITPI3qxgvc7mWqE4aN5DCknyYy2hfL/MC85lzKjMybxnsP452T83JQNPMg
JIpHoA001DH88A0=
JIpHoA001DH88A0=
"]]</lang>
"]]</syntaxhighlight>


=={{header|TXR}}==
=={{header|TXR}}==
Line 3,581: Line 3,581:
Note one detail: in the first verse we have "... don't know why she swallowed the fly". But in subsequent verses it is
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>).
"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>).
<lang txr>@(deffilter abbr
<syntaxhighlight lang="txr">@(deffilter abbr
("IK" "I know an old lady who swallowed a") ("SW" "She swallowed the")
("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")
("SS" "she swallowed") ("CA" "to catch the") ("XX" "Perhaps she'll die")
Line 3,663: Line 3,663:
@song
@song
@ (end)
@ (end)
@(end)</lang>
@(end)</syntaxhighlight>


=={{header|UNIX Shell}}==
=={{header|UNIX Shell}}==
{{works_with|Bash}}
{{works_with|Bash}}
<lang sh>animals=(fly spider bird cat dog pig goat cow donkey horse)
<syntaxhighlight lang="sh">animals=(fly spider bird cat dog pig goat cow donkey horse)
comments=("I don't know why she swallowed that fly"
comments=("I don't know why she swallowed that fly"
"That wriggled and jiggled and tickled inside her"
"That wriggled and jiggled and tickled inside her"
Line 3,695: Line 3,695:
echo
echo
fi
fi
done</lang>
done</syntaxhighlight>


=={{header|Ursa}}==
=={{header|Ursa}}==
{{trans|C#}}
{{trans|C#}}
<lang ursa>decl string<> reason creatures comments
<syntaxhighlight lang="ursa">decl string<> reason creatures comments
append "She swallowed the " " to catch the " reason
append "She swallowed the " " to catch the " reason
append "fly" "spider" "bird" "cat" "dog" "goat" "cow" "horse" creatures
append "fly" "spider" "bird" "cat" "dog" "goat" "cow" "horse" creatures
Line 3,724: Line 3,724:
end for
end for
end for
end for
in string console</lang>
in string console</syntaxhighlight>


=={{header|VBScript}}==
=={{header|VBScript}}==
<syntaxhighlight lang="vb">
<lang vb>
a=array( _
a=array( _
array("fly",""),_
array("fly",""),_
Line 3,758: Line 3,758:
print b1
print b1
next
next
</syntaxhighlight>
</lang>
=={{header|Vlang}}==
=={{header|Vlang}}==
<lang vlang>const (
<syntaxhighlight lang="vlang">const (
name = 0
name = 0
lyric = 1
lyric = 1
Line 3,791: Line 3,791:
println("${animals[0][lyric]}\n")
println("${animals[0][lyric]}\n")
}
}
}</lang>
}</syntaxhighlight>


{{out}}
{{out}}
Line 3,849: Line 3,849:
=={{header|Wren}}==
=={{header|Wren}}==
{{trans|Kotlin}}
{{trans|Kotlin}}
<lang ecmascript>var animals = ["fly", "spider", "bird", "cat","dog", "goat", "cow", "horse"]
<syntaxhighlight lang="ecmascript">var animals = ["fly", "spider", "bird", "cat","dog", "goat", "cow", "horse"]


var phrases = [
var phrases = [
Line 3,879: Line 3,879:
}
}


sing.call()</lang>
sing.call()</syntaxhighlight>


=={{header|Z80 Assembly}}==
=={{header|Z80 Assembly}}==
Line 3,885: Line 3,885:
Press any key to print each verse. After the last verse, press any key to return to BASIC.
Press any key to print each verse. After the last verse, press any key to return to BASIC.


<lang z80>waitChar equ &BB06
<syntaxhighlight lang="z80">waitChar equ &BB06
PrintChar equ &BB5A
PrintChar equ &BB5A


Line 4,054: Line 4,054:
byte " to catch the ",0
byte " to catch the ",0
Song_NewLine:
Song_NewLine:
byte 13,10,0 ;control codes for a new line.</lang>
byte 13,10,0 ;control codes for a new line.</syntaxhighlight>


=={{header|zkl}}==
=={{header|zkl}}==
{{trans|Tcl}}
{{trans|Tcl}}
Uncompresses the base64 encoded gziped text of the song. Uses shared libraries zlib and msg hashing for the codecs.
Uncompresses the base64 encoded gziped text of the song. Uses shared libraries zlib and msg hashing for the codecs.
<lang zkl>var ZLib=Import("zeelib"), MsgHash=Import("zklMsgHash");
<syntaxhighlight lang="zkl">var ZLib=Import("zeelib"), MsgHash=Import("zklMsgHash");
text:=
text:=
"eJztlE1uwyAQhdflFOOVNyhXyLap1FV7AWKIoaFMBFjIt++M7YVpLfVHilQp2cHMg3l8T+IA"
"eJztlE1uwyAQhdflFOOVNyhXyLap1FV7AWKIoaFMBFjIt++M7YVpLfVHilQp2cHMg3l8T+IA"
Line 4,069: Line 4,069:


MsgHash.base64decode(text) :
MsgHash.base64decode(text) :
ZLib.Inflator().write(_).close().read().text.println();</lang>
ZLib.Inflator().write(_).close().read().text.println();</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>