Old lady swallowed a fly: Difference between revisions
Content added Content deleted
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
|||
Line 13: | Line 13: | ||
{{trans|Python}} |
{{trans|Python}} |
||
< |
<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()</ |
print()</syntaxhighlight> |
||
=={{header|8080 Assembly}}== |
=={{header|8080 Assembly}}== |
||
< |
<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,'$'</ |
comma: db ',',13,10,'$'</syntaxhighlight> |
||
=={{header|8086 Assembly}}== |
=={{header|8086 Assembly}}== |
||
< |
<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,'$'</ |
comma: db ',',13,10,'$'</syntaxhighlight> |
||
=={{header|Ada}}== |
=={{header|Ada}}== |
||
< |
<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;</ |
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''.}} |
||
< |
<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!")</ |
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''.}} |
||
< |
<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</ |
OD</syntaxhighlight> |
||
=={{header|APL}}== |
=={{header|APL}}== |
||
{{works with|Dyalog APL}} |
{{works with|Dyalog APL}} |
||
< |
<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 |
||
}</ |
}</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" </ |
comma: .asciz ",\n" </syntaxhighlight> |
||
=={{header|AutoHotkey}}== |
=={{header|AutoHotkey}}== |
||
{{works with|AutoHotkey 1.1}} |
{{works with|AutoHotkey 1.1}} |
||
< |
<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</ |
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}}== |
||
< |
<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}}== |
||
< |
<syntaxhighlight lang="dos">@echo off |
||
setlocal enabledelayedexpansion |
setlocal enabledelayedexpansion |
||
Line 568: | Line 568: | ||
) |
) |
||
:done |
:done |
||
pause>nul&exit/b 0</ |
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. |
||
< |
<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</ |
ENDPROC</syntaxhighlight> |
||
=={{header|BCPL}}== |
=={{header|BCPL}}== |
||
< |
<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)</ |
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. |
||
< |
<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!|</ |
ead, of course!|</syntaxhighlight> |
||
=={{header|C}}== |
=={{header|C}}== |
||
< |
<syntaxhighlight lang="c">#include <stdio.h> |
||
static char const *animals[] = { |
static char const *animals[] = { |
||
"fly", |
"fly", |
||
Line 682: | Line 682: | ||
} |
} |
||
} |
} |
||
}</ |
}</syntaxhighlight> |
||
=={{header|C sharp|C#}}== |
=={{header|C sharp|C#}}== |
||
< |
<syntaxhighlight lang="csharp">using System; |
||
namespace OldLady |
namespace OldLady |
||
Line 725: | Line 725: | ||
} |
} |
||
} |
} |
||
}</ |
}</syntaxhighlight> |
||
=={{header|C++}}== |
=={{header|C++}}== |
||
{{trans|C#}} |
{{trans|C#}} |
||
< |
<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; |
||
}</ |
}</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}}== |
||
< |
<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</ |
end start_up</syntaxhighlight> |
||
=={{header|COBOL}}== |
=={{header|COBOL}}== |
||
< |
<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)=== |
||
< |
<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. |
||
< |
<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. |
||
< |
<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. |
||
< |
<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): |
||
< |
<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. ~%~%"))))))</ |
(format t "Perhaps she'll die. ~%~%"))))))</syntaxhighlight> |
||
{{Out}} |
{{Out}} |
||
Line 1,263: | Line 1,263: | ||
=={{header|Cowgol}}== |
=={{header|Cowgol}}== |
||
< |
<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;</ |
end loop;</syntaxhighlight> |
||
=={{header|D}}== |
=={{header|D}}== |
||
{{trans|C}} |
{{trans|C}} |
||
< |
<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; |
||
}</ |
}</syntaxhighlight> |
||
A more structured alternative version: |
A more structured alternative version: |
||
< |
<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; |
||
} |
} |
||
}</ |
}</syntaxhighlight> |
||
=={{header|Draco}}== |
=={{header|Draco}}== |
||
< |
<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</ |
corp</syntaxhighlight> |
||
=={{header|Elena}}== |
=={{header|Elena}}== |
||
ELENA 5.0 : |
ELENA 5.0 : |
||
< |
<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() |
||
} |
} |
||
}</ |
}</syntaxhighlight> |
||
=={{header|Elixir}}== |
=={{header|Elixir}}== |
||
{{trans|Ruby}} |
{{trans|Ruby}} |
||
< |
<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</ |
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. |
||
< |
<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</ |
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. |
||
< |
<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!" ;</ |
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}}== |
||
< |
<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</ |
next verse</syntaxhighlight> |
||
=={{header|Free Pascal}}== |
=={{header|Free Pascal}}== |
||
< |
<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. |
||
< |
<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</ |
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] |
||
< |
<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") |
||
} |
} |
||
}</ |
}</syntaxhighlight> |
||
=={{header|Haskell}}== |
=={{header|Haskell}}== |
||
< |
<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)</ |
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): |
||
< |
<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</ |
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. |
||
< |
<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</ |
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. |
||
< |
<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!'</ |
e'She''s dead, of course!'</syntaxhighlight> |
||
=={{header|Java}}== |
=={{header|Java}}== |
||
{{Trans|C| via [[#D|D]]}} |
{{Trans|C| via [[#D|D]]}} |
||
< |
<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); |
||
} |
} |
||
}</ |
}</syntaxhighlight> |
||
=={{header|Julia}}== |
=={{header|Julia}}== |
||
{{works with|Julia|0.6}} |
{{works with|Julia|0.6}} |
||
< |
<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))))</ |
println(String(transcode(ZlibDecompressor(), base64decode(b64))))</syntaxhighlight> |
||
< |
<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</ |
end</syntaxhighlight> |
||
=={{header|Kotlin}}== |
=={{header|Kotlin}}== |
||
< |
<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() |
||
}</ |
}</syntaxhighlight> |
||
=={{header|Lambdatalk}}== |
=={{header|Lambdatalk}}== |
||
< |
<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}}== |
||
< |
<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</ |
bye</syntaxhighlight> |
||
=={{header|Lua}}== |
=={{header|Lua}}== |
||
< |
<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</ |
end</syntaxhighlight> |
||
=={{header|MAD}}== |
=={{header|MAD}}== |
||
< |
<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 </ |
END OF PROGRAM </syntaxhighlight> |
||
=={{header|Maple}}== |
=={{header|Maple}}== |
||
< |
<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;</ |
end do;</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 2,525: | Line 2,525: | ||
=={{header|Mathematica}}/{{header|Wolfram Language}}== |
=={{header|Mathematica}}/{{header|Wolfram Language}}== |
||
< |
<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])];</ |
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}}== |
||
< |
<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).</ |
swallowed(fly, !IO).</syntaxhighlight> |
||
=={{header|Modula-2}}== |
=={{header|Modula-2}}== |
||
< |
<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.</ |
END OldLady.</syntaxhighlight> |
||
=={{header|Nanoquery}}== |
=={{header|Nanoquery}}== |
||
{{trans|Ursa}} |
{{trans|Ursa}} |
||
< |
<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()</ |
input()</syntaxhighlight> |
||
=={{header|Nim}}== |
=={{header|Nim}}== |
||
{{trans|Python}} |
{{trans|Python}} |
||
{{libheader|nim-lang/zip}} |
{{libheader|nim-lang/zip}} |
||
< |
<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()</ |
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): |
||
< |
<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</ |
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]: |
||
< |
<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</ |
old_lady dict.(0) false</syntaxhighlight> |
||
===Using Logic=== |
===Using Logic=== |
||
< |
<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!"</ |
She's dead, of course!"</syntaxhighlight> |
||
=={{header|Perl}}== |
=={{header|Perl}}== |
||
Using string subst:< |
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; |
||
}</ |
}</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). |
||
< |
<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== |
||
====</ |
====</syntaxhighlight> |
||
=={{header|Phix}}== |
=={{header|Phix}}== |
||
{{Trans|Ada}} |
{{Trans|Ada}} |
||
<!--< |
<!--<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> |
||
<!--</ |
<!--</syntaxhighlight>--> |
||
=={{header|PHP}}== |
=={{header|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"; |
||
}</ |
}</syntaxhighlight> |
||
=={{header|PicoLisp}}== |
=={{header|PicoLisp}}== |
||
{{trans|C}} |
{{trans|C}} |
||
< |
<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))</ |
(oldLady (car *Dict))</syntaxhighlight> |
||
=={{header|PL/M}}== |
=={{header|PL/M}}== |
||
< |
<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</ |
EOF</syntaxhighlight> |
||
=={{header|PowerShell}}== |
=={{header|PowerShell}}== |
||
< |
<syntaxhighlight lang="powershell"> |
||
$lines = @( |
$lines = @( |
||
'fly/' |
'fly/' |
||
Line 3,136: | Line 3,136: | ||
"Perhaps she'll die." |
"Perhaps she'll die." |
||
"" |
"" |
||
}</ |
}</syntaxhighlight> |
||
=={{header|Python}}== |
=={{header|Python}}== |
||
< |
<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"))</ |
print(zlib.decompress(base64.b64decode(b64)).decode("utf-8", "strict"))</syntaxhighlight> |
||
< |
<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</ |
print() # new line</syntaxhighlight> |
||
=={{header|R}}== |
=={{header|R}}== |
||
< |
<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}}== |
||
< |
<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: |
||
< |
<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 |
<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,"); |
||
}</ |
}</syntaxhighlight> |
||
And that's how I larned it! |
And that's how I larned it! |
||
=={{header|REXX}}== |
=={{header|REXX}}== |
||
< |
<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. */</ |
end /*j*/ /*stick a fork in it, we're all done. */</syntaxhighlight> |
||
{{out|output|text= (with the lyrics being centered):}} |
{{out|output|text= (with the lyrics being centered):}} |
||
<pre> |
<pre> |
||
Line 3,365: | Line 3,365: | ||
=={{header|Ruby}}== |
=={{header|Ruby}}== |
||
< |
<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</ |
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] |
||
< |
<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"); |
||
} |
} |
||
}</ |
}</syntaxhighlight> |
||
=={{header|Scala}}== |
=={{header|Scala}}== |
||
< |
<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 |
||
} |
} |
||
}</ |
}</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}}== |
||
< |
<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;</ |
end func;</syntaxhighlight> |
||
=={{header|Sidef}}== |
=={{header|Sidef}}== |
||
{{trans|Raku}} |
{{trans|Raku}} |
||
< |
<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},"); |
||
};</ |
};</syntaxhighlight> |
||
=={{header|Tcl}}== |
=={{header|Tcl}}== |
||
Because the song is highly repetitive, it compresses wonderfully. |
Because the song is highly repetitive, it compresses wonderfully. |
||
< |
<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= |
||
"]]</ |
"]]</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>). |
||
< |
<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)</ |
@(end)</syntaxhighlight> |
||
=={{header|UNIX Shell}}== |
=={{header|UNIX Shell}}== |
||
{{works_with|Bash}} |
{{works_with|Bash}} |
||
< |
<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</ |
done</syntaxhighlight> |
||
=={{header|Ursa}}== |
=={{header|Ursa}}== |
||
{{trans|C#}} |
{{trans|C#}} |
||
< |
<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</ |
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}}== |
||
< |
<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") |
||
} |
} |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 3,849: | Line 3,849: | ||
=={{header|Wren}}== |
=={{header|Wren}}== |
||
{{trans|Kotlin}} |
{{trans|Kotlin}} |
||
< |
<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()</ |
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. |
||
< |
<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.</ |
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. |
||
< |
<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();</ |
ZLib.Inflator().write(_).close().read().text.println();</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |