Ticket #87 (closed enhancement: fixed)

Opened 3 years ago

Last modified 3 years ago

__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:1 Changed 3 years ago by jorgenpt

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.

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$

comment:4 Changed 3 years ago by mooneer

  • Status changed from closed to reopened
  • Resolution worksforme deleted

Oops, didn't see the other bit.

comment:5 Changed 3 years ago by mooneer

  • Status changed from reopened to closed
  • Resolution set to fixed

In as of r555.

Note: See TracTickets for help on using tickets.