Say you have a record or class:
record R {
var value: int;
}
How can I access the field value by using the string "value"?
For example, in Python, you can access fields using the getattr built-in:
class C:
def __init__(self, val):
self.value = val
c = C(2)
print(getattr(c, 'value')) # prints 2
What would this look like in Chapel?
The
Reflectionmodule'sgetField()andgetFieldRef()routines provide this capability. For example, the following program both reads and writes the field 'value' (TIO):