Ticket #87 (closed enhancement: fixed)
__str__ or __repr__-like feature
| Reported by: | jorgenpt | Owned by: | mooneer |
|---|---|---|---|
| Priority: | minor | Milestone: | |
| Component: | interpreter | Version: | 1.0.1 |
| Keywords: | Cc: |
Description
Kite should have a default stringification method that produces a string that (if possible) gives the information needed to recreate an identical object. Something similar to python's repr (repr() method and %r format calls repr on the object to get the representation, and a default one that merely displays something like memory address and class name).
This would be very useful, especially if it was embedded in ikt, so that each expressions value was displayed using this method (so one's able to inspect the variables and return values one has).
Change History
comment:2 Changed 3 years ago by jorgenpt
Sorry, here it is, wrapped in pre:
ikt> i = 'foo'; j = 'bar'; 'bar' ikt> i|length; 3 ikt> complexobject; SomeClass [foo=2]
comment:3 Changed 3 years ago by mooneer
- Status changed from new to closed
- Version set to 1.0.1
- Resolution set to worksforme
Kite already has a |str method to do what you want:
harry:build mooneer$ bin/ikt
This is ikt, version 1.0.2 (built on i386-apple-darwin9.6.0)
Copyright (C) 2008 Mooneer Salem. All rights reserved
ikt> import "System.regex";
ikt> p = 5;
ikt> q = make System.regex("X");
ikt> p|str|print;
5
ikt> q|str|print;
System.regex
ikt>
harry:build mooneer$

Suggested ikt-session:
ikt> i = 'foo'; j = 'bar'; 'bar' ikt> i|length; 3
This would be similar to the "print"-method, but rather show a set of data more suitable for debugging and whatnot.