RosettaCodeData/Task/Comma-quibbling/Logo/comma-quibbling.logo
2015-02-20 09:02:09 -05:00

26 lines
653 B
Text

to join :delimiter :list [:result []]
output cond [
[ [empty? :list] :result ]
[ [empty? :result] (join :delimiter butfirst :list first :list) ]
[ else (join :delimiter butfirst :list
(word :result :delimiter first :list)) ]
]
end
to quibble :list
local "length
make "length count :list
make "text (
ifelse [:length <= 2] [
(join "\ and\ :list)
] [
(join "\ and\ (sentence join ",\ butlast :list last :list))
])
output ifelse [empty? :text] "\{\} [(word "\{ :text "\})]
end
foreach [ [] [ABC] [ABC DEF] [ABC DEF G H] ] [
print quibble ?
]
bye