AppleScript’s handling of multidimensional lists often proceeds at a glacial pace, so I prefer to avoid lists of lists whenever possible. This presents a special problem when a function needs to return two or more lists to its caller.
When a function must return two or more values, it’s a simple matter to place the values in a list, and return that.
Similar can done with lists, by creating a one dimensional list holding the count of the first list, the values of the first list, the count of the second list, the values of the second list, etc. etc.
Here’s a little code I use for functions that must return two or three lists. The general case, returning n lists, likely wouldn’t be too hard to write, but so far variants on these two tidbits have met my needs.
To see what they do, open up the Editors “Result” pane before running them.
-- Avoid multidimensional lists in function returns
-- by packing and unpacking a 1D list
-- 2 lists
-- BP 2011
set pkg to pack2Lists()
set ra1count to item 1 of pkg
set ra2count to item (ra1count + 2) of pkg -- (const is 1 + previous number of items)
set ra1 to items 2 thru (ra1count + 1) of pkg
set ra2 to items (ra1count + 3) thru (ra1count + ra2count + 2) of pkg
return ra1 --ra2 --pkg -- change the returned variable to see what's in each List.
---------------
on pack2Lists()
set ra1 to {1, 2, 3, 4, 5, 6}
set ra2 to {"kk", "rest", "muck", "twenty"}
set rez to (count of ra1) & ra1 & (count of ra2) & ra2
return rez
end pack2Lists
-- Avoid multidimensional lists in function returns
-- by packing and unpacking a 1D list
-- 3 Lists
-- BP 2011
set pkg to pack3Lists()
set ra1count to item 1 of pkg
set ra2count to item (ra1count + 2) of pkg
set ra3count to item (ra1count + ra2count + 3) of pkg -- (const is 1 + previous number of items)
set ra1 to items 2 thru (ra1count + 1) of pkg
set ra2 to items (ra1count + 3) thru (ra1count + ra2count + 2) of pkg
set ra3 to items (ra1count + ra2count + 4) thru (ra1count + ra2count + ra3count + 3) of pkg
return pkg --ra1 -- ra2 --ra3 -- change the returned variable to see what's in each List.
---------------
on pack3Lists()
set ra1 to {1, 2, 3, 4, 5, 6}
set ra2 to {"kk", "rest", "muck", "twenty"}
set ra3 to {7, 9, 4, 3, 22}
set rez to (count of ra1) & ra1 & (count of ra2) & ra2 & (count of ra3) & ra3
return rez
end pack3Lists