Hacker News new | ask | show | jobs
by kazinator 1368 days ago
This is called print-read consistency in the Lisp world: an object is printed in such a way that the syntax can be read to produce a similar object, or else is given a deliberately unreadable notation like #<...>, where the #< combination is required to produce a read error.

https://stackoverflow.com/questions/70797208/what-is-print-r...

1 comments

Thanks for this

I've had this notion in my head, of making variables capable of echoing out their own definition when printed for easier time writing tests/debugging

Didn't know it had a name

In Python, there is a distinction between the text representation of an object, and the result of converting the object to a string. Classes can implement both methods independently, and it's not uncommon to have a repr method that returns something that you could (at least in theory) evaluate as literal Python code. This is very useful for debugging and logging, although not nearly as cool or powerful as the Lisp equivalent.