Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
18
Task/Comma-quibbling/REBOL/comma-quibbling-1.rebol
Normal file
18
Task/Comma-quibbling/REBOL/comma-quibbling-1.rebol
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
Rebol []
|
||||
|
||||
comma-quibbling: func [block] [
|
||||
rejoin [
|
||||
"^{"
|
||||
|
||||
to-string use [s] [
|
||||
s: copy block
|
||||
s: next s
|
||||
forskip s 2 [insert s either tail? next s [" and "] [", "]]
|
||||
s: head s
|
||||
]
|
||||
|
||||
"^}"
|
||||
]
|
||||
]
|
||||
|
||||
foreach t [[] [ABC] [ABC DEF] [ABC DEF G H]] [print comma-quibbling t]
|
||||
24
Task/Comma-quibbling/REBOL/comma-quibbling-2.rebol
Normal file
24
Task/Comma-quibbling/REBOL/comma-quibbling-2.rebol
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
Rebol []
|
||||
|
||||
; builds string instead of using an intermediate block
|
||||
|
||||
comma-quibbling: func [block /oxford /local s length] [
|
||||
length: length? block
|
||||
rejoin [
|
||||
"^{"
|
||||
|
||||
either length < 2 [to-string block] [
|
||||
s: to-string block/1
|
||||
for n 2 (length - 1) 1 [repend s [", " pick block n]]
|
||||
if all [oxford (length > 2)] [append s ","]
|
||||
repend s [" and " last block]
|
||||
]
|
||||
|
||||
"^}"
|
||||
]
|
||||
]
|
||||
|
||||
test: [[] [ABC] [ABC DEF] [ABC DEF G H]]
|
||||
foreach t test [print comma-quibbling t]
|
||||
print "Now with Oxford comma"
|
||||
foreach t test [print comma-quibbling/oxford t]
|
||||
Loading…
Add table
Add a link
Reference in a new issue