Simple Arrays

Dick Kriesel dick.kriesel at mail.com
Mon Jan 11 15:10:37 EST 2010


On 1/10/10 1:25 PM, "Phil Davis" <revdev at pdslabs.net> wrote:

> The things some people do for fun...  ;-)

... can make others want to get in on the fun, like by fixing something that
ain't broke.  Here's an elaboration on your idea that handles your sample
data more than twice as fast, primarily by avoiding the "do" for typical
cases.

Thanks for the cue, Phil.

-- Dick


<postscript_with_line_wraps>

function table_split tTable,pLineDel,pItemDel
   filter tTable without empty
   set the lineDelimiter to coalesce(pLineDel,cr)
   set the itemDelimiter to coalesce(pItemDel,tab)
   switch number of items in line 1 of tTable - 1 -- number of dimensions
      case 1
         repeat for each line tLine in tTable
            put item 2 of tLine into tArray[item 1 of tLine]
         end repeat
         break
      case 2
         repeat for each line tLine in tTable
            put item 3 of tLine into tArray[item 1 of tLine][item 2 of
tLine]
         end repeat
         break  
      case 3
         repeat for each line tLine in tTable
            put item 4 of tLine into tArray[item 1 of tLine][item 2 of
tLine][item 3 of tLine]
         end repeat
         break  
      default      
         repeat for each line tLine in tTable
            do "put last item of tLine into tArray[" & replaceText(item 1 to
-2 of tLine,the itemDelimiter,"][") & "]"
         end repeat
   end switch
   return tArray 
end table_split

function coalesce -- return the first non-empty parameter
   repeat with i = 1 to the paramCount
      if param(i) is not empty then
         return param(i)
      end if   
   end repeat
end coalesce

</postscript_with_line_wraps>





More information about the use-livecode mailing list