Skip to content

Instantly share code, notes, and snippets.

@Oldes
Last active October 31, 2020 22:48
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save Oldes/ed3ae5f88644979a3bd5ee640f6be73a to your computer and use it in GitHub Desktop.
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