Get list of instance variables?

Is it possible to get a list of the instance variables of some object?

(
p = Ppar([
  Pbind(),
  Pbind()
])
)

p.dump shows me the variables, but is it possible to receive this information in the language?

Not really ideal to go behind the back of an object’s public interface, but it is possible to introspect:

x = Point(1, 2);  // any object

x.class.instVarNames
-> SymbolArray[x, y]

(
d = IdentityDictionary.new;
x.class.instVarNames.do { |name|
	d.put(name, x.slotAt(name))
};
d
)
-> IdentityDictionary[(x -> 1), (y -> 2)]

(slotAt gives you access to info that an object might “officially” keep private; its companion method slotPut is dangerous because you can overwrite an object’s private vars. So use caution – SC allows you to shoot yourself in the foot here, but that doesn’t mean it’s a good idea.)

hjh

This is deep, thank you

The reason I was asking is because I’m interested in searching through an arbitrary pattern to find all instances of a particular class (in this case a custom pattern class which I want to adjust in bulk after creation… But simple version of the problem is, find all the instances of Pfunc in some arbitrary pattern). The only way I could think of was to recursively check the instance vars for each nested pattern to see if any contains another pattern, etc… But maybe you know a better way?