Old lady swallowed a fly: Difference between revisions

m
syntax highlighting fixup automation
m (syntax highlighting fixup automation)
Line 13:
{{trans|Python}}
 
<langsyntaxhighlight lang="11l">V animals = [
(‘fly’, ‘I don't know why she swallowed a fly, perhaps she'll die.’),
(‘spider’, ‘It wiggled and jiggled and tickled inside her.’),
Line 36:
I animal != ‘fly’
print(animals[0][1])
print()</langsyntaxhighlight>
 
=={{header|8080 Assembly}}==
<langsyntaxhighlight lang="8080asm"> org 100h
mvi c,-1 ; C = verse counter
verse: inr c
Line 110:
swlw1: db 'She swallowed the $'
swlw2: db ' to catch the $'
comma: db ',',13,10,'$'</langsyntaxhighlight>
 
=={{header|8086 Assembly}}==
<langsyntaxhighlight lang="asm"> cpu 8086
org 100h
section .text
Line 177:
swlw1: db 'She swallowed the $'
swlw2: db ' to catch the $'
comma: db ',',13,10,'$'</langsyntaxhighlight>
 
=={{header|Ada}}==
<langsyntaxhighlight Adalang="ada">with Ada.Text_IO, Ada.Containers.Indefinite_Doubly_Linked_Lists; use Ada.Text_IO;
 
procedure Swallow_Fly is
Line 237:
Put_Line("There was an old lady who swallowed a horse ...");
Put_Line("She's dead, of course!");
end Swallow_Fly;</langsyntaxhighlight>
 
=={{header|ALGOL 68}}==
Line 244:
{{works with|ALGOL 68G|Any - tested with release [http://sourceforge.net/projects/algol68/files/algol68g/algol68g-1.18.0/algol68g-1.18.0-9h.tiny.el5.centos.fc11.i386.rpm/download 1.18.0-9h.tiny].}}
{{wont work with|ELLA ALGOL 68|Any (with appropriate job cards) - tested with release [http://sourceforge.net/projects/algol68/files/algol68toc/algol68toc-1.8.8d/algol68toc-1.8-8d.fc9.i386.rpm/download 1.8-8d] - due to extensive use of '''format'''[ted] ''transput''.}}
<langsyntaxhighlight lang="algol68">#!/usr/local/bin/a68g --script #
 
STRING sw=" swallow ",swd=sw[:UPB sw-1]+"ed ", tsa=". To"+sw+"a";
Line 277:
vs("Cow",("I don't know how",tsa));
vs("Donkey",("It was rather wonky",tsa));
vs("Horse","She's dead, of course!")</langsyntaxhighlight>
 
===Using a dictionary===
Line 283:
{{works with|ALGOL 68G|Any - tested with release [http://sourceforge.net/projects/algol68/files/algol68g/algol68g-1.18.0/algol68g-1.18.0-9h.tiny.el5.centos.fc11.i386.rpm/download 1.18.0-9h.tiny].}}
{{wont work with|ELLA ALGOL 68|Any (with appropriate job cards) - tested with release [http://sourceforge.net/projects/algol68/files/algol68toc/algol68toc-1.8.8d/algol68toc-1.8-8d.fc9.i386.rpm/download 1.8-8d] - due to extensive use of '''format'''[ted] ''transput''.}}
<langsyntaxhighlight lang="algol68">#!/usr/local/bin/a68g --script #
 
STRING a="WBXAY",b="WCXBY",c="WDXCY",d="WEXDY",
Line 321:
OD;
print(new line)
OD</langsyntaxhighlight>
 
=={{header|APL}}==
{{works with|Dyalog APL}}
<langsyntaxhighlight APLlang="apl">oldLady←{
N←⎕TC[3]
a←'fly' 'spider' 'bird' 'cat' 'dog' 'goat' 'cow' 'horse'
Line 344:
}¨⌽1↓⍳⍵
}¨⍳8
}</langsyntaxhighlight>
 
=={{header|ARM Assembly}}==
<syntaxhighlight lang="text">.global _start
_start: eor r8,r8,r8 @ Verse counter
verse: add r8,r8,#1 @ Next verse
Line 414:
swa1: .asciz "She swallowed the "
swa2: .asciz " to catch the "
comma: .asciz ",\n" </langsyntaxhighlight>
 
=={{header|AutoHotkey}}==
{{works with|AutoHotkey 1.1}}
<langsyntaxhighlight AutoHotkeylang="autohotkey">Animals := [["fly", "I don't know why she swallowed the "]
, ["spider", "That wriggled and jiggled and tickled inside her"]
, ["bird", "Quite absurd"]
Line 436:
}
 
MsgBox, % Output</langsyntaxhighlight>
 
=={{header|AWK}}==
<syntaxhighlight lang="awk">
<lang AWK>
# syntax: GAWK -f OLD_LADY_SWALLOWED_A_FLY.AWK
BEGIN {
Line 473:
exit(0)
}
</syntaxhighlight>
</lang>
 
=={{header|Babel}}==
<langsyntaxhighlight lang="babel">((main {fly !})
 
(fly
Line 520:
("spider" "That wriggled and jiggled and tickled inside her")
("fly" " "))))
</syntaxhighlight>
</lang>
 
=={{header|Batch File}}==
<langsyntaxhighlight lang="dos">@echo off
setlocal enabledelayedexpansion
 
Line 568:
)
:done
pause>nul&exit/b 0</langsyntaxhighlight>
 
=={{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.
<langsyntaxhighlight lang="bbcbasic">REM >oldlady
DIM swallowings$(6, 1)
swallowings$() = "fly", "+why", "spider", "That wriggled and wiggled and tickled inside her", "bird", ":How absurd", "cat", ":Fancy that", "dog", ":What a hog", "cow", "+how", "horse", "She's dead, of course"
Line 599:
PRINT observation$; "!"
ENDCASE
ENDPROC</langsyntaxhighlight>
 
=={{header|BCPL}}==
<langsyntaxhighlight lang="bcpl">get "libhdr"
 
let animal(n) =
Line 631:
$)
 
let start() be for n=0 to 7 do verse(n)</langsyntaxhighlight>
 
=={{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.
 
<langsyntaxhighlight 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<
>$ 36 26 58 49 81 36 26 10 \1-:#^\_^#:-1\+<00_@#:>#<$<
Line 644:
.|Fancy that$Dog-.|What a hog$Pig7.|Her mouth was so big%Goat=.|She just opened
her throat$Cow3.|I don't know how'Donkey6.|It was rather wonky&Horse:.|She's d
ead, of course!|</langsyntaxhighlight>
 
=={{header|C}}==
<langsyntaxhighlight lang="c">#include <stdio.h>
static char const *animals[] = {
"fly",
Line 682:
}
}
}</langsyntaxhighlight>
 
=={{header|C sharp|C#}}==
<langsyntaxhighlight lang="csharp">using System;
 
namespace OldLady
Line 725:
}
}
}</langsyntaxhighlight>
 
=={{header|C++}}==
{{trans|C#}}
<langsyntaxhighlight lang="cpp">#include <iostream>
 
const char *CREATURES[] = { "fly", "spider", "bird", "cat", "dog", "goat", "cow", "horse" };
Line 756:
 
return 0;
}</langsyntaxhighlight>
{{out}}
<pre>There was an old lady who swallowed a fly
Line 817:
 
=={{header|CLU}}==
<langsyntaxhighlight lang="clu">old_lady = cluster is swallow
rep = null
Line 857:
start_up = proc ()
old_lady$swallow(stream$primary_output())
end start_up</langsyntaxhighlight>
 
=={{header|COBOL}}==
<langsyntaxhighlight lang="cobol"> IDENTIFICATION DIVISION.
PROGRAM-ID. OLD-LADY.
 
Line 950:
DISPLAY LINE-OUT.
</syntaxhighlight>
</lang>
 
=={{header|Commodore BASIC}}==
Line 958:
 
===Commodore BASIC (No Sound)===
<langsyntaxhighlight lang="gwbasic">
1 rem rosetta code
2 rem old lady who swallowed a fly
Line 992:
1070 data "cow","I don't know how she swallowed a cow!"
1080 data "horse","...She died, of course!"
</syntaxhighlight>
</lang>
 
===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.
<langsyntaxhighlight lang="gwbasic">
1 rem rosetta code
2 rem old lady who swallowed a fly - c64
Line 1,063:
2550 for i=1 to 8:for j=1 to 3:read mu$(i,j):next j:next i
2599 return
</syntaxhighlight>
</lang>
 
===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.
<langsyntaxhighlight lang="gwbasic">
1 rem rosetta code
2 rem old lady who swallowed a fly - plus/4
Line 1,135:
2550 for i=1 to 8:for j=1 to 3:read mu$(i,j):next j:next i
2599 return
</syntaxhighlight>
</lang>
 
===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.
<langsyntaxhighlight lang="gwbasic">
1 rem rosetta code
2 rem old lady who swallowed a fly - c128
Line 1,191:
2520 play "v1o4t0u5"
2599 return
</syntaxhighlight>
</lang>
 
=={{header|Common Lisp}}==
A rather iterative, rather than recursive solution. The lyrics match the original Burl Ives recording (not the later animated cartoon):
 
<langsyntaxhighlight lang="lisp">(defun verse (what remark &optional always die) (list what remark always die))
(defun what (verse) (first verse))
(defun remark (verse) (second verse))
Line 1,232:
(if (always v)
(format t "~a~a~%" (if (= j 0) "But " "") (remark v))))))
(format t "Perhaps she'll die. ~%~%"))))))</langsyntaxhighlight>
 
{{Out}}
Line 1,263:
 
=={{header|Cowgol}}==
<langsyntaxhighlight lang="cowgol">include "cowgol.coh";
 
var animals: [uint8][] := {
Line 1,303:
i := i + 1;
end loop;</langsyntaxhighlight>
 
=={{header|D}}==
{{trans|C}}
<langsyntaxhighlight lang="d">import core.stdc.stdio;
 
immutable data = [
Line 1,335:
void main() {
data[0].oldLady;
}</langsyntaxhighlight>
 
A more structured alternative version:
<langsyntaxhighlight lang="d">enum Action { once, every, die }
 
immutable struct T {
Line 1,378:
"Perhaps she'll die.\n".writeln;
}
}</langsyntaxhighlight>
 
=={{header|Draco}}==
<langsyntaxhighlight lang="draco">proc nonrec animal(byte n) *char:
case n
incase 0: "fly"
Line 1,425:
byte n;
for n from 0 upto 7 do verse(n) od
corp</langsyntaxhighlight>
 
=={{header|Elena}}==
ELENA 5.0 :
<langsyntaxhighlight lang="elena">import extensions;
const Creatures = new string[]{"fly", "spider", "bird", "cat", "dog", "goat", "cow", "horse"};
Line 1,464:
console.writeLine()
}
}</langsyntaxhighlight>
 
=={{header|Elixir}}==
{{trans|Ruby}}
<langsyntaxhighlight lang="elixir">defmodule Old_lady do
@descriptions [
fly: "I don't know why S",
Line 1,515:
end
 
Old_lady.swallowed</langsyntaxhighlight>
 
=={{header|Factor}}==
Windows users should put zlib1.dll[http://downloads.factorcode.org/dlls/] to factor folder.
<langsyntaxhighlight lang="factor">USING: base85 compression.zlib ;
 
"c%1E4%WlIU5WMphn^P`UexSD=s^-?Jk$NVE7-Gs=fQ9_`T}Y~ggi4hvMSb{SX}vpQXJ;^Yqok7%xd(0
Line 1,528:
<}rUt#FCDtKB9S`Y4jg+0PuB?Qt-&(11p?caq^S=1C`$D1fa<y6|YD*77a{4949T_-MVet;6abaEn"
 
base85> 3215 <compressed> uncompress >string print</langsyntaxhighlight>
 
=={{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.
<langsyntaxhighlight lang="forth">: string, ( c-addr u -- ) \ store string at HERE , with a count
dup c, here swap dup allot move ;
 
Line 1,585:
first @ begin dup verse cr >next dup 0= until drop
cr ." There was an old lady who swallowed a horse..."
cr ." She's dead, of course!" ;</langsyntaxhighlight>
 
=={{header|Fortran}}==
<syntaxhighlight lang="fortran">
<lang Fortran>
program fly
!A program to print the "Old lady swallowed a fly" poem
Line 1,627:
end program fly
</syntaxhighlight>
</lang>
 
=={{header|FreeBASIC}}==
<langsyntaxhighlight 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!" },_
{ "spider", "That wriggled and jiggled and tickled inside her!" },_
Line 1,652:
next countdown
print
next verse</langsyntaxhighlight>
 
=={{header|Free Pascal}}==
<langsyntaxhighlight Freelang="free Pascalpascal">(* A mixture of the lyrics found in Wikipedia and the Ada version
in Rosetta Code. It formats the lyrics like the Wikipedia one *)
program OldLady;
Line 1,735:
PrintSong;
end.
</syntaxhighlight>
</lang>
 
=={{header|Frege}}==
Line 1,743:
Nearly identical to the Haskell. Only the first line of the program is different.
 
<langsyntaxhighlight lang="frege">module OldLady where
 
import Data.List
Line 1,783:
song = concatMap verse $ tail $ reverse $ tails animals
 
main = putStr $ unlines song</langsyntaxhighlight>
 
=={{header|Go}}==
[https://play.golang.org/p/OV3YJSWxaJP Go Playground]
<langsyntaxhighlight lang="go">package main
 
import "fmt"
Line 1,824:
fmt.Println(animals[0][lyric] + "\n")
}
}</langsyntaxhighlight>
 
=={{header|Haskell}}==
 
<langsyntaxhighlight lang="haskell">import Data.List (tails)
 
animals :: [String]
Line 1,856:
putStr $
concatMap unlines $
zipWith (:) beginnings $ reverse $ ([] :) (tails lastVerse)</langsyntaxhighlight>
{{out}}<pre>There was an old lady who swallowed a fly.
I don't know why she swallowed a fly.
Line 1,923:
And a variation on this theme (a little more disaggregated):
 
<langsyntaxhighlight lang="haskell">import Prelude hiding (lookup)
import Data.Map.Strict (Map, fromList, lookup)
import Data.List (inits, intercalate)
Line 1,984:
 
comments :: Map String String
comments = fromList courses</langsyntaxhighlight>
{{Out}}
<pre>There was an old lady who swallowed a fly;
Line 2,050:
=={{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.
<langsyntaxhighlight Iconlang="icon">procedure main() #: There Was An Old Lady Lyrics
 
verse := table() # arglists for printf - [1] long asides and [2] terse joiners
Line 2,081:
end
 
link printf</langsyntaxhighlight>
Sample output omitted.
 
Line 2,089:
=={{header|J}}==
This defines T to be the required text.
<langsyntaxhighlight lang="j">T=:''
e=:3 :'T=:T,y,LF'
E=:e@,&'.'
Line 2,112:
'Donkey'N'It was rather wonky'
O'Horse'
e'She''s dead, of course!'</langsyntaxhighlight>
 
=={{header|Java}}==
{{Trans|C| via [[#D|D]]}}
<langsyntaxhighlight lang="java">public class OldLadySwallowedAFly {
 
final static String[] data = {
Line 2,144:
oldLady(data[0], false);
}
}</langsyntaxhighlight>
 
=={{header|Julia}}==
{{works with|Julia|0.6}}
 
<langsyntaxhighlight lang="julia">using CodecZlib
 
b64 = b"""eNrtVE1rwzAMvedXaKdeRn7ENrb21rHCzmrs1m49K9gOJv9+cko/HBcGg0LHcpOfnq2np0QL
Line 2,158:
Mz3XkPBc/TSN3yxGiqMiipHRekycK0ZwMhM8jerGC9zuZaoTho3kMKSfJjLaF8v8wLzmXMqM
zJvGew/jnZPzclA08yAkikegDTTUMfzwDXBcwoE="""
println(String(transcode(ZlibDecompressor(), base64decode(b64))))</langsyntaxhighlight>
 
<langsyntaxhighlight lang="julia">animals = [
("fly", "I don't know why she swallowed a fly, perhaps she'll die."),
("spider", "It wiggled and jiggled and tickled inside her."),
Line 2,181:
if animal != "fly" println(animals[1][2]) end # fly lyric
println() # new line
end</langsyntaxhighlight>
 
=={{header|Kotlin}}==
<langsyntaxhighlight lang="scala">// version 1.1.3
 
val animals = listOf("fly", "spider", "bird", "cat","dog", "goat", "cow", "horse")
Line 2,218:
fun main(args: Array<String>) {
sing()
}</langsyntaxhighlight>
 
=={{header|Lambdatalk}}==
<langsyntaxhighlight lang="scheme">
{def A {A.new fly spider bird cat dog goat cow horse}}
-> A
Line 2,295:
There was an old lady who swallowed a horse
She's dead of course
</syntaxhighlight>
</lang>
 
=={{header|Liberty BASIC}}==
<syntaxhighlight lang="lb">
<lang lb>
'[RC] Old lady swallowed a fly
'http://rosettacode.org/wiki/Old_lady_swallowed_a_fly
Line 2,344:
 
end
</syntaxhighlight>
</lang>
 
=={{header|Logo}}==
<langsyntaxhighlight lang="logo">make "data [
; animal inc comment
[fly 2 [I don't know why she swallowed that fly]]
Line 2,381:
]
 
bye</langsyntaxhighlight>
 
=={{header|Lua}}==
<langsyntaxhighlight lang="lua">animals = {"fly", "spider", "bird", "cat","dog", "goat", "cow", "horse"}
phrases = {
"",
Line 2,413:
end
io.write("I don't know why she swallowed a fly - Perhaps she'll die!\n\n")
end</langsyntaxhighlight>
 
=={{header|MAD}}==
<langsyntaxhighlight MADlang="mad"> NORMAL MODE IS INTEGER
INTERNAL FUNCTION(V)
Line 2,458:
VERSE WHENEVER J.LE.2, VERSE.(J-1)
END OF PROGRAM </langsyntaxhighlight>
 
=={{header|Maple}}==
<langsyntaxhighlight lang="maple">swallowed := ["fly", "spider", "bird", "cat", "dog", "cow", "horse"]:
phrases := ["I don't know why she swallowed a fly, perhaps she'll die!",
"That wriggled and wiggled and tiggled inside her.",
Line 2,479:
printf("\n");
end if;
end do;</langsyntaxhighlight>
{{out}}
<pre>
Line 2,525:
 
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<langsyntaxhighlight Mathematicalang="mathematica">animals = {"fly", "spider", "bird", "cat", "dog", "goat", "cow",
"horse"};
notes = {"", "That wiggled and jiggled and tickled inside her.\n",
Line 2,541:
StringJoin @@ ("She swallowed the " <> animals[[#]] <>
" to catch the " <> animals[[# - 1]] <> ".\n" & /@
Range[#, 2, -1]) <> notes[[9]]] & /@ Range[8])];</langsyntaxhighlight>
{{out}}
<pre>There was an old lady who swallowed a fly.
Line 2,602:
 
=={{header|Mercury}}==
<langsyntaxhighlight Mercurylang="mercury">:- module oldlady.
:- interface.
:- import_module io.
Line 2,674:
 
main(!IO) :-
swallowed(fly, !IO).</langsyntaxhighlight>
 
=={{header|Modula-2}}==
<langsyntaxhighlight lang="modula2">MODULE OldLady;
FROM FormatString IMPORT FormatString;
FROM Terminal IMPORT WriteString,WriteLn,ReadChar;
Line 2,728:
 
ReadChar
END OldLady.</langsyntaxhighlight>
 
=={{header|Nanoquery}}==
{{trans|Ursa}}
<langsyntaxhighlight lang="nanoquery">reason = {"She swallowed the ", " to catch the "}
creatures = {"fly", "spider", "bird", "cat", "dog", "goat", "cow", "horse"}
comments = {"I don't know why she swallowed that fly.\nPerhaps she'll die\n",\
Line 2,755:
end
 
input()</langsyntaxhighlight>
 
=={{header|Nim}}==
{{trans|Python}}
{{libheader|nim-lang/zip}}
<langsyntaxhighlight lang="nim">import zip/zlib, base64
 
const b64 = """
Line 2,771:
zJvGew/jnZPzclA08yAkikegDTTUMfzwDXBcwoE="""
 
echo b64.decode.uncompress()</langsyntaxhighlight>
 
=={{header|OCaml}}==
===Using a dictionary===
Only one minimalist line of code (the last line):
<langsyntaxhighlight lang="ocaml">let d = [|
"I know an old lady who swallowed a "; "fly"; ".\n";
"I don't know why she swallowed the fly.\nPerhaps she'll die.\n\n";
Line 2,807:
[23] ;;
 
List.iter (fun i -> print_string d.(i)) s</langsyntaxhighlight>
===Using dictionary based decompression===
{{trans|D}}
Here we use the function <code ocaml>String.fold_left</code> [http://ocaml-extlib.googlecode.com/svn/doc/apiref/ExtString.String.html#VALfold_left 1] which is not available in the standard library but in the [http://code.google.com/p/ocaml-extlib/ extlib]:
<langsyntaxhighlight lang="ocaml">let dict = [|
"_ha _c _e _p,\nQuite absurd_f_p;_`cat,\nFancy that_fcat;_j`dog,\nWhat a hog_\
fdog;_l`pig,\nHer mouth_qso big_fpig;_d_r,\nShe just opened her throat_f_r;_i\
Line 2,829:
let _ =
old_lady dict.(0) false</langsyntaxhighlight>
===Using Logic===
<langsyntaxhighlight lang="ocaml">let an =
[| "fly"; "spider"; "bird"; "cat"; "dog"; "pig"; "goat"; "cow"; "donkey" |]
 
Line 2,862:
for i = 0 to 8 do f i done;
p "There was an old lady who swallowed a horse...\n\
She's dead, of course!"</langsyntaxhighlight>
 
=={{header|Perl}}==
Using string subst:<langsyntaxhighlight lang="perl">my @animals = (
"fly",
"spider/That wriggled and jiggled and tickled inside her.\n",
Line 2,896:
s/:.*/--\nShe's dead, of course!\n/s;
print;
}</langsyntaxhighlight>
Using compression:
(Assumes a Unix-like OS and the availability of the uudecode and bunzip2 utilities).
<langsyntaxhighlight lang="perl">open OUT, "| uudecode | bunzip2" and
print OUT <DATA> and
close OUT;
Line 2,916:
FeXUOI8486Wvor1zajqPDfpwnrn2jOzvo8hkOPrpVajlwnjqPfIry5c0TbKL
559fx8xqpsquRaFYV9I9fT6p7RrI/Gv/F3JFOFCQRJtf/Q==
====</langsyntaxhighlight>
 
=={{header|Phix}}==
{{Trans|Ada}}
<!--<langsyntaxhighlight Phixlang="phix">(phixonline)-->
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #004080;">sequence</span> <span style="color: #000000;">lines</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{</span><span style="color: #008000;">"Perhaps she'll die!\n"</span><span style="color: #0000FF;">},</span> <span style="color: #000000;">animals</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{}</span>
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: #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>
<!--</langsyntaxhighlight>-->
 
=={{header|PHP}}==
<langsyntaxhighlight lang="php"><?php
 
$swallowed = array(
Line 2,991:
else
print "Perhaps she'll die." . "\n\n";
}</langsyntaxhighlight>
 
=={{header|PicoLisp}}==
{{trans|C}}
<langsyntaxhighlight PicoLisplang="picolisp">(de *Dict
`(chop
"_ha _c _e _p,/Quite absurd_f_p;_`cat,/Fancy that_fcat;_j`dog,\
Line 3,036:
Flg )
 
(oldLady (car *Dict))</langsyntaxhighlight>
 
=={{header|PL/M}}==
<langsyntaxhighlight lang="plm">100H:
 
/* CP/M CALL */
Line 3,101:
 
CALL BDOS(0,0);
EOF</langsyntaxhighlight>
 
=={{header|PowerShell}}==
<langsyntaxhighlight lang="powershell">
$lines = @(
'fly/'
Line 3,136:
"Perhaps she'll die."
""
}</langsyntaxhighlight>
 
=={{header|Python}}==
<langsyntaxhighlight lang="python">import zlib, base64
 
b64 = b'''
Line 3,149:
Mz3XkPBc/TSN3yxGiqMiipHRekycK0ZwMhM8jerGC9zuZaoTho3kMKSfJjLaF8v8wLzmXMqM
zJvGew/jnZPzclA08yAkikegDTTUMfzwDXBcwoE='''
print(zlib.decompress(base64.b64decode(b64)).decode("utf-8", "strict"))</langsyntaxhighlight>
 
<langsyntaxhighlight lang="python">animals = [
("fly", "I don't know why she swallowed a fly, perhaps she'll die."),
("spider", "It wiggled and jiggled and tickled inside her."),
Line 3,170:
 
if animal != "fly": print(animals[0][1]) # fly lyric
print() # new line</langsyntaxhighlight>
 
=={{header|R}}==
<langsyntaxhighlight Rlang="r">animals = list(
c("fly", "I don't know why she swallowed a fly, perhaps she'll die."),
c("spider", "It wiggled and jiggled and tickled inside her."),
Line 3,205:
oldladysnack <- oldladysnack + 1
}
</syntaxhighlight>
</lang>
 
=={{header|Racket}}==
<langsyntaxhighlight lang="racket">
#lang at-exp racket
 
Line 3,233:
@line{}
(loop more (cons animal seen)))])))
</syntaxhighlight>
</lang>
Alternative solution:
<langsyntaxhighlight lang="racket">
#lang s-exp framework/private/decode
7VK7TsQwEOz9FcM1AcncZyCoQaLey/piCyuObJ+s/D3rXHj4lIIKgaCItJkZ7cyOfM0uTZ5m
Line 3,242:
U+SaYuVXditxxdu8b338rOvEUas7GvuVa44Tcuu2/qz7CHuu6PeWwGHQ6rmiBCtz24KwWy0I
3KZdqvwDbfWhXPhY+S59RLX5dkTapF66/2/3fYMNMZklVJfAhlgjHKW2k8B7tbtRrw==
</syntaxhighlight>
</lang>
 
=={{header|Raku}}==
(formerly Perl 6)
<syntaxhighlight lang="raku" perl6line>my @victims =
fly => " I don't know why S—",
spider => " That wriggled and jiggled and tickled inside her.",
Line 3,270:
@history.unshift($_) if @history < 5;
@history.unshift("X to catch the $victim,");
}</langsyntaxhighlight>
And that's how I larned it!
 
=={{header|REXX}}==
<langsyntaxhighlight 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.*/
@.=; @.1 = "I don't know why she swallowed a fly,"
Line 3,297:
say center(@.1, sw)
say center("I guess she'll die.", sw)
end /*j*/ /*stick a fork in it, we're all done. */</langsyntaxhighlight>
{{out|output|text=&nbsp; (with the lyrics being centered):}}
<pre>
Line 3,365:
 
=={{header|Ruby}}==
<langsyntaxhighlight lang="ruby">descriptions = {
:fly => "I don't know why S",
:spider => "That wriggled and jiggled and tickled inside her.",
Line 3,396:
 
print "Perhaps she'll die.\n\n"
end</langsyntaxhighlight>
 
=={{header|Rust}}==
[https://play.rust-lang.org/?gist=294c9e29f206d7c8d8028aa5e7002d9a&version=nightly Rust Playground]
<langsyntaxhighlight lang="rust">enum Action {Once, Every, Die}
use Action::*;
 
Line 3,431:
println!("Perhaps she'll die.\n");
}
}</langsyntaxhighlight>
 
=={{header|Scala}}==
<langsyntaxhighlight Scalalang="scala">case class Verse(animal: String, remark: String, die: Boolean = false, always: Boolean = false)
 
val verses = List(
Line 3,460:
println
}
}</langsyntaxhighlight>
{{out}}
<pre>There was an old lady who swallowed a fly,
Line 3,489:
 
=={{header|Seed7}}==
<langsyntaxhighlight lang="seed7">$ include "seed7_05.s7i";
 
const array array string: verses is [] (
Line 3,522:
end if;
end for;
end func;</langsyntaxhighlight>
 
=={{header|Sidef}}==
{{trans|Raku}}
<langsyntaxhighlight lang="ruby">var victims = [
:fly: " I don't know why S—",
:spider: " That wriggled and jiggled and tickled inside her.",
Line 3,553:
history.len < 5 && history.unshift(verse);
history.unshift("X to catch the #{victim},");
};</langsyntaxhighlight>
 
=={{header|Tcl}}==
Because the song is highly repetitive, it compresses wonderfully.
<langsyntaxhighlight lang="tcl">package require Tcl 8.6
 
puts [zlib inflate [binary decode base64 "
Line 3,568:
nCtGcDITPI3qxgvc7mWqE4aN5DCknyYy2hfL/MC85lzKjMybxnsP452T83JQNPMg
JIpHoA001DH88A0=
"]]</langsyntaxhighlight>
 
=={{header|TXR}}==
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
"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>).
<langsyntaxhighlight lang="txr">@(deffilter abbr
("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")
Line 3,663:
@song
@ (end)
@(end)</langsyntaxhighlight>
 
=={{header|UNIX Shell}}==
{{works_with|Bash}}
<langsyntaxhighlight lang="sh">animals=(fly spider bird cat dog pig goat cow donkey horse)
comments=("I don't know why she swallowed that fly"
"That wriggled and jiggled and tickled inside her"
Line 3,695:
echo
fi
done</langsyntaxhighlight>
 
=={{header|Ursa}}==
{{trans|C#}}
<langsyntaxhighlight lang="ursa">decl string<> reason creatures comments
append "She swallowed the " " to catch the " reason
append "fly" "spider" "bird" "cat" "dog" "goat" "cow" "horse" creatures
Line 3,724:
end for
end for
in string console</langsyntaxhighlight>
 
=={{header|VBScript}}==
<syntaxhighlight lang="vb">
<lang vb>
a=array( _
array("fly",""),_
Line 3,758:
print b1
next
</syntaxhighlight>
</lang>
=={{header|Vlang}}==
<langsyntaxhighlight lang="vlang">const (
name = 0
lyric = 1
Line 3,791:
println("${animals[0][lyric]}\n")
}
}</langsyntaxhighlight>
 
{{out}}
Line 3,849:
=={{header|Wren}}==
{{trans|Kotlin}}
<langsyntaxhighlight lang="ecmascript">var animals = ["fly", "spider", "bird", "cat","dog", "goat", "cow", "horse"]
 
var phrases = [
Line 3,879:
}
 
sing.call()</langsyntaxhighlight>
 
=={{header|Z80 Assembly}}==
Line 3,885:
Press any key to print each verse. After the last verse, press any key to return to BASIC.
 
<langsyntaxhighlight lang="z80">waitChar equ &BB06
PrintChar equ &BB5A
 
Line 4,054:
byte " to catch the ",0
Song_NewLine:
byte 13,10,0 ;control codes for a new line.</langsyntaxhighlight>
 
=={{header|zkl}}==
{{trans|Tcl}}
Uncompresses the base64 encoded gziped text of the song. Uses shared libraries zlib and msg hashing for the codecs.
<langsyntaxhighlight lang="zkl">var ZLib=Import("zeelib"), MsgHash=Import("zklMsgHash");
text:=
"eJztlE1uwyAQhdflFOOVNyhXyLap1FV7AWKIoaFMBFjIt++M7YVpLfVHilQp2cHMg3l8T+IA"
Line 4,069:
 
MsgHash.base64decode(text) :
ZLib.Inflator().write(_).close().read().text.println();</langsyntaxhighlight>
{{out}}
<pre>
10,327

edits