-->
function nest(sequence input)
if length(input) then
for level=max(input) to 2 by -1 do
sequence output = {}
bool subnest = false
for i=1 to length(input) do
object ii = input[i]
if integer(ii) and ii<level then
subnest = false
output &= ii
elsif not subnest then
output &= {{ii}}
subnest = true
else
output[$] &= {ii}
end if
end for
input = output
end for
end if
return input
end function