Old lady swallowed a fly: Difference between revisions

Content added Content deleted
(→‎{{header|jq}}: def cond(_;_))
Line 2,300: Line 2,300:


def sing:
def sing:
def cond(q; x): select(q) | x;
range(0; animals|length) as $i
range(0;8)
| "There was an old lady who swallowed a \(animals[$i]);",
( phrases[$i] // empty | "\(.)!" ),
| "There was an old lady who swallowed a \(animals[.]);",
( if $i < 7
cond(. > 0; "\(phrases[.])"),
then "",
cond(. < 7;
(if $i > 0
"",
then range($i; 0; -1) as $j
cond(. > 0;
range(.; 0; -1) as $j
| " She swallowed the \(animals[$j]) to catch the \(
animals[$j - 1])\(if $j < 3 then ";" else "," end)",
| " She swallowed the \(animals[$j]) to catch the \(
(select($j == 2) | " \(phrases[1])!")
animals[$j - 1])\(if $j < 3 then ";" else "," end)",
cond($j == 2; " \(phrases[1])!") ),
else empty
" I don't know why she swallowed a fly - Perhaps she'll die!\n" );
end),
" I don't know why she swallowed a fly - Perhaps she'll die!\n"
else empty
end) ;


sing
sing