[I6] Debugging Variables

Dear all,

for debugging purposes I want to display the value of variables. Ideally I would have a function DEBUG that prints out the value of a variable, be it integer or string. Like, I have a variable “i” which is an integer, and a variable “text” which is a string, and I’d like to call
DEBUG (i);
DEBUG (text);
How do I accomplish that?

Thanks and kind regards,
Grues

This is not completely possible. I6 doesn’t have typed variables, so a given value could be either an address or a number. (You can distinguish string, function, and object addresses.)

You can fake it by assuming that any small number is not an address:

[ DEBUG val;
    if (val < 256) print_ret "DEBUG number ", val;
    if (metaclass(val) == Routine) print_ret "DEBUG function";
    if (metaclass(val) == Object) print_ret "DEBUG object ", (name)val;
    if (metaclass(val) == String) print_ret "DEBUG string ", (string)val;
    print_ret "DEBUG other";
];

(Code not tested.)

Uuhhh, “Metaclass()” - didn’t know that function exists. That should indeed do the trick, I’m just after strings and numbers. Thaaaanks!

And thanks again, Zarf! Works like a charm. I don’t know how I could live my former life without this… :slight_smile: