Last active
October 31, 2020 22:48
-
-
Save Oldes/ed3ae5f88644979a3bd5ee640f6be73a to your computer and use it in GitHub Desktop.
This file contains 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 [ | |
name: enlist | |
purpose: "Format series to human readable list" | |
usage: [ | |
print enlist [] ;= none | |
print enlist [1] ;= just 1 | |
print enlist [1 2] ;= 1 and 2 | |
print enlist [1 2 3] ;= 1, 2 and 3 | |
] | |
note: https://gitter.im/red/help?at=5f9c02f906fa0513dd8119d1 | |
] | |
enlist: function [ | |
"Format series to human readable list" | |
block [block!] | |
][ | |
ajoin switch/default len: length? block [ | |
0 [[none]] | |
1 [["just " block/1]] | |
][ | |
i: 1 out: clear "" | |
loop len - 2 [ append append out block/(++ i) ", " ] | |
[out block/:i " and " block/:len] | |
] | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment