View/Edit #29:english_list

Switch to edit mode.

Name(s): english_list
1:  "Prints the argument as an english list, e.g. {1, 2, 3} is printed as '1, 2, and 3', and {1, 2} is printed as '1 and 2'."
2:  "Optional arguments are treated as follows:"
3:  "  Second argument is the string to use when the empty list is given.  The default is 'nothing'."
4:  "  Third argument is the string to use in place of ' and '.  A typical application might be to use ' or ' instead."
5:  "  Fourth argument is the string to use instead of a comma (and space)."
6:  "  Fifth argument is a string to use after the penultimate element before the ' and '.  The default is to have a comma without a space."
7:  {things, ?nothingstr = "nothing", ?andstr = " and ", ?commastr = ", ", ?finalcommastr = ","} = args
8:  if (typeof(things) != $LIST)
9:    return tostr(things)
10: endif
11: nthings = length(things)
12: if (nthings == 0)
13:   return nothingstr
14: elseif (nthings == 1)
15:   return tostr(things[1])
16: elseif (nthings == 2)
17:   return tostr(things[1], andstr, things[2])
18: else
19:   ret = ""
20:   for k in [1..nthings - 1]
21:     if (k == nthings - 1)
22:       commastr = finalcommastr
23:     endif
24:     ret = tostr(ret, things[k], commastr)
25:   endfor
26:   return tostr(ret, andstr, things[nthings])
27: endif
28: "Last modified by Dax (#789) on Wed May  4 06:46:00 2005 MDT."

Verb arguments: this none this
Verb perms: Readable eXecutable NOT-Debug
Verb owned by: Hacker (#60)

You are not logged in.

[home | help | who | search | setup | code]