comparing lists of offsets

I’m trying to compare lists of offsets, and having a problem which involves nested lists.

It’s hard to explain so let me show you the variables in question:

property mf: {1,2}
property newidmatches: {1,2}

set nimf to {}
repeat with aMf in mf
if aMf is in newidmatches then copy aMf to the end of nimf
end repeat

nimf: {item 1 of {1,2}, item 2 of {1,2}}

the result I want is:
nimf : {1,2}

how do I get that?


I think I just answered my own question:

property mf : {1, 2}
property newidmatches : {1, 2}

set nimf to {}
repeat with i3 from 1 to count mf
if item i3 of mf is in newidmatches then copy item i3 of mf to the end of nimf
end repeat

set result to nimf

{1, 2}

seems cumbersome though (just one extra index variable in a big nest). any way to get the first syntax to work?

The ‘repeat with’ loop assigns a reference to a list item to variable aMf. (It’s a common mistake to assume it assigns the item itself.) To retrieve the item being referenced, get the reference’s contents property:

repeat with aMfRef in mf
    if aMfRef's contents is in newidmatches then set the end of nimf to aMfRef's contents
end repeat