if Length(a) > 1 then
begin
s := String.Join(', ', a, 0, Length(a)-1);
s := s + ' and ' + a[High(a)]
end
else
begin
if Length(a) > 0 then
s := a[0]
else
s :='';
end;
assumes a is of type array of string
matchlen(a):
case1: s = a[0]
case2: s = ' and '.join(a)
case _:
s = ', '.join(a[:-1])
s = s + ', and ' + a[-1]
classList:
def__init__(self):
self.m = []
defapply(self, /, *x, y='', z=''):
self.m.append((x, y, z))
defparse(self, x):
x = [*map(str, x)]
for a, y, z in self.m:
for i in a: x[i] = y + x[i] + z
return''.join(x)
x = List()
match n := len(a):
case1: ...
case2: x.apply(0, z=' and ')
case _:
x.apply(*range(n - 1), z=', ')
x.apply(-1, y='and ')
s = x.parse(a)
This function will apply a prefix and suffix, given a sequence of index values, x.
remainder, last = a[..-2], a[-1]
s = remainder.join(", ") + "#{' and 'unless remainder.empty?}" + last.to_s
if Length(a) > 1 then
begin
s := String.Join(', ', a, 0, Length(a)-1);
s := s + ' and ' + a[High(a)]
end
else
begin
if Length(a) > 0 then
s := a[0]
else
s :='';
end;
class List:
def __init__(self):
self.m = []
def apply(self, /, *x, y='', z=''):
self.m.append((x, y, z))
def parse(self, x):
x = [*map(str, x)]
for a, y, z in self.m:
for i in a: x[i] = y + x[i] + z
return ''.join(x)
x = List()
match n := len(a):
case 1: ...
case 2: x.apply(0, z=' and ')
case _:
x.apply(*range(n - 1), z=', ')
x.apply(-1, y='and ')
s = x.parse(a)