If I try to add a new either / or property to all objects with the following code:
An object can be frotzable.
An object is usually not frotzable.
the set of objects to which the property will be added won’t include the objects Compass, thedark, VPH_2, and VPH_24. And that’s probably a good call - it’s unlikely that I intended to add a property to Compass or thedark, and I don’t even know what VPH_2 and VPH_24 are.
But when I try to iterate over all objects with the following code:
repeat with o running through objects:
the set of objects over which o iterates will include the objects Compass, thedark, VPH_2, and VPH_24. That means that I can’t iterate over frotzable objects with a filtered loop like this:
repeat with o running through frotzable objects:
because those four objects don’t provide the property “frotzable” and I get 8 “[** Programming error: tried to read (something) **]” runtime errors - probably because that kind of filtered loop tries to query the property twice for each object. I can’t even use an unfiltered loop with an if statement like this:
repeat with o running through objects:
if o is frotzable:
because again, those four objects are included in the loop, and querying the frotzable property in the if statement produces 4 “[** Programming error: tried to read (something) **]” runtime errors. To make it work, I have to add yet another if statement:
repeat with o running through objects:
if o provides property frotzable:
if o is frotzable:
Is there a reason for this difference between the set of objects referred to by “an object can be x” and the set of objects referred to by “repeat with o running through objects:”?
And if it’s not a bug, shouldn’t the compiler reject “repeat with o running through x objects” loops that filter the kind “object” by an either / or property? They’ll always produce runtime errors.
And is there a way to filter out those four objects from a loop that I’ve missed?