Created
January 15, 2014 15:48
-
-
Save draegtun/8438614 to your computer and use it in GitHub Desktop.
Some comma quibbling in Rebol
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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