merge lists


[ Zettels Traum ] [ search / suche ]

von dp am 23.August 98 um 18:11:15:

zu: compare lists von dp am 14.Februar 97 um 20:42:28:

Director 6 still has no function to merge lists, despite many posts asked for.
In short, merging (concatenating) lists is making one list out of 2 or more:
[ 1, #lira ] and [ "=", [ 0.001, "SFr" ] ] become
[1, #lira, "=" [ 0.001, "SFr" ] ]
OK, I recently said "no unnecessary keywords, please", now I have to pay for:
Here is the handler.
It works EVEN WITH HUGE LISTS, i.e., length( string( hugeList ) ) > 32767.
That's the reason why I did it (not my joking about too much keywords),
you will see more clarity in this point in the following posts (grr!).
Call this function with the syntax:
myMergedList = mergeLists( list1, list2, ... )
--------------------------------------------------------------------------
on mergeLists
  -- Merges lists of the same type into one list.
  if listP( param( 1 ) ) then
    if the paramCount = 1 then return param( 1 )
    set newList = duplicate( param( 1 ) )
    set listType = ilk( newList )
  else
    alert "ERROR in handler mergeLists: First argument is not a list."
    return VOID
  end if
  repeat with i = 2 to the paramCount
    if not( ilk( param( i ) ) ) = listType then
      alert "ERROR in handler mergeLists: Argument" && i && 
        "is not of the same list type as argument 1."
      return VOID
    end if
    if listType = #proplist then
      repeat with j = 1 to count( param( i ) )
        addProp( newList, getPropAt( param( i ), j ), getAt( param( i ), j ) )
      end repeat
    else
      repeat with j = 1 to count( param( i ) )
        add( newList, getAt( param( i ), j ) )
      end repeat
    end if
  end repeat
  return newList
end mergeLists
--------------------------------------------------------------------------

Andreas




Dazu:























D. Plänitz