4 ms·
Sure. What kind of string? For debugging? If so, is a recursive? For output to a log? For output to a widget in a UI? To a string suitable for a report? What en
by thelazydogsback 7y ago
Sure. What kind of string? For debugging? If so, is a recursive? For output to a log? For output to a widget in a UI? To a string suitable for a report? What encoding? What language?
- earenndil 7y agoWhy not add an expectation, then, for what kind of string it is? You just have to have one. E.G. perl has .perl, which has the constraint that, for any obj, it should be that obj == (EVAL obj.perl). It doesn't matter what that is, as long as you agree on it. Having objects that know how to print themselves isn't intrinsically problematic.
- thelazydogsback 7y agoThat is serialization, which is one purpose for converting to a string. Dynamic languages already tend to be able to print objects in a way that's meaningful -- such as most REPL-based languages that have a reader (or eval) and a printer. As do ML-derived languages the print in constructor format, but they tend not to have readers or eval. Having it called .perl in this case is already a step in the right direction from toString, as you know what its for.