Introspection¶
Small helpers for inspecting objects at runtime: identity, a debug representation, and a list of keys.
| Function | Description |
|---|---|
var id(var obj) |
The object's memory address as an int. |
var repr(var obj) |
A debug string: <AbsObj Type=<n> Addr=<p>>. |
var dir(var obj) |
Dictionary keys, or list indices, as a list (empty for everything else). |
var d = Dict();
dset(d, "name", v("abscom"));
dset(d, "level", v(9));
print(dir(d)); /* [name, level] */
print(id(d)); /* e.g. 696235936 */
print(repr(d)); /* <AbsObj Type=5 Addr=00000205...> */
Notes:
idis the object pointer cast to an int — stable while the object lives, unique per live object.reprround-trips theAbsTypevalue and the address; combine it withtype()for a readable name.diron a list yields0, 1, 2, ...; on a dict it yields the keys (insertion order is not guaranteed).- Each
id()/repr()/dir()call returns a fresh object, so compare values (e.g.id(a)->val.i == id(b)->val.i), not pointers.
Back to README.