Skip to content

Instantly share code, notes, and snippets.

@draegtun
Created January 15, 2014 15:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save draegtun/8438614 to your computer and use it in GitHub Desktop.
Save draegtun/8438614 to your computer and use it in GitHub Desktop.
Some comma quibbling in Rebol
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
]
Rebol []
; a recursive version
comma-quibbling: func [block /local sub-quibble] [
sub-quibble: func [words] [
switch/default length? words [
0 [""]
1 [words/1]
2 [rejoin [words/1 " and " words/2]]
][
insert words rejoin [take words ", " take words]
sub-quibble words
]
]
rejoin [ "^{" sub-quibble copy block "^}" ]
]
test: [[] [ABC] [ABC DEF] [ABC DEF G H]]
foreach t test [print comma-quibbling t]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment