At 20:29 06.01.2001 +0000, Yo Gomi wrote:
>Hello, Lingo-Ls
>Does anybody know how to count members in a list?
>For example:
>MyList=[#d,#a,#b,#c,#b,#a]
>I want the lingo to find out that within myList, there are 2 of #a, 2 of #b,
>1 of #c and 1 of #d.
>If I do myList.count it only gives me the total of 6.
>Any suggestion greatly appreciated. Thanks in advance. Yo
Yo,
the handler below was originally written to sum up partial results from
propLists with integer Values but it handles linear lists, too.
-- Welcome to Director --
LpResults= [:]
LToCount= [#d,#a,#b,#c,#b,#a]
put addtoProp (LpResults,LToCount)
-- [#d: 1, #a: 2, #b: 2, #c: 1]
Lp1= [#apples:2,#peaches:3,#nuts:1]
Lp2= [#apples:1,#peaches:1,#nuts:4]
put addtoProp (Lp1,Lp2)
-- [#apples: 3, #peaches: 4, #nuts: 5]
-- movieScript -----------------------
on addToProp dLp,dLp2
-- the first List will be returned
-- with the prop/Val or Vals of the second list added
if dLp.ilk <> #propList then return
if not ListP(dLp2) then return
ilktest = dLp2.ilk
cnt =dLp2.count
repeat with index = 1 to cnt
if ilktest = #propList then
dProp = dLp2.getPropAt(index)
dVal = dLp2[index]
else
dProp = dLp2[index]
dVal = 1
end if
dtest = dLp.getaProp(dProp)
if voidP(dTest) then
dLp.setaprop(dProp,dVal)
else
dLp[dProp] = dTest + dVal
end if
end repeat
return dLp
end
best regards
daniel plaenitz
[To remove yourself from this list, or to change to digest mode, go to
http://www.penworks.com/LUJ/lingo-l.cgi To post messages to the list,
email [EMAIL PROTECTED] (Problems, email [EMAIL PROTECTED])
Lingo-L is for learning and helping with programming Lingo. Thanks!]