Object.prototype.inspect ?

P T Withington ptw at pobox.com
Thu Mar 12 17:41:55 PDT 2009

On 2009-03-12, at 18:49EDT, Brendan Eich wrote:

> On Mar 12, 2009, at 1:33 PM, Brendan Eich wrote:
>> On Mar 12, 2009, at 3:54 AM, Tobie Langel wrote:
>>> On Mar 11, 2009, at 21:32 , Brendan Eich wrote:
>>>> Want to help?
>>> Sure. How?
>> The discussion here should focus on use-cases, which will help us  
>> write down requirements and anti-requirements. If we only care  
>> about diagnostic inspection, not round-tripping equivalent object  
>> graphs (the two are not always cleanly separable), we should say  
>> what does round trip, what does not (native data including method  
>> references, e.g.).
> So [0,1,[2,3]] => "[0, 1, [2, 3]]" is good for both hi-fi serialize/ 
> deserialize value recovery, and (I claim) for human inspection. But  
> a really long and/or deep array structure would be unreadable, so  
> ellipses might be appropriate for the human in the loop. IMHO we  
> should borrow from Python (again) on pragmatic stuff like eliding  
> overlong repr strings.

I invite you to play around with the OpenLaszlo Debugger, which has  
borrow heavily from Lisp (skipping the Python filter :).  You can see  
some examples in the documentation of the formatted output '%w'  
directive: http://xrl.us/bejep3 or you can get down to the nitty- 
gritty and read the source of the LzDebugService/__String method: http://xrl.us/bejeqd

Since our classes mostly implement a DOM-like structure, we use a  
pseudo-xpath syntax to abbreviate objects that are contained in other  
objects (although I haven't worried about circular objects yet).  For  
example, here's what the typical user might see if they are inspecting  
a <button id="mybutton"> object's subnode array:

lzx> Debug.inspect(«Array(6)| [#myButton/@_outerbezel, #myButton…»)
«Array(6)#48| [#myButton/@_outerbezel, #myButton/@_innerbezel…» {
   0: #myButton/@_outerbezel
   1: #myButton/@_innerbezel
   2: #myButton/@_face
   3: #myButton/@_innerbezelbottom
   4: #myButton/@_outerbezelbottom
   5: #myButton/@_title
«Array(6)#48| [#myButton/@_outerbezel, #myButton/@_innerbezel,  
#myButton/@_face, #myButton/@_innerbezelbottom, #myButton/ 
@_outerbezelbottom, #myButton/@_title]»

More information about the Es-discuss mailing list