In answer to Michael's question:
assume the structure is not circular
same deterministic result each time
depth first

In sort at least a simple list of lists should work with no surprises.



On Mon, Mar 10, 2014 at 2:59 PM, Michael Glass <[email protected]>wrote:

> Your desire to recursively traverse structures opens up several issues,
> viz:
>
> -- The order of traversing structures: depth-first or breadth first.
> -- Do you want to render the same structure twice
> -- How to handle circular structures: A points to B points to A...
>
> Here are the same structure twice and circularity questions:
>
>    L1 := ['a', 'b']
>    L2 := [L1, L1]
>    put(L2, L2)
>    writeany(L2)
>
> How do you want L2 to display?  Do you want to render and print L1
> multiple times, even if it is a big complicated mess? What about the
> L2-inside-L2 problem?
>
> You might want to look at the Image() function in the Icon library. Many
> (!) years ago I beefed it up to do the kind of thing you are talking about.
> It is a bit messy, partly because there is an option to display tree
> structure in indented fashion. It handles only lists, records, sets, and
> tables. In other words, it handles only pre-Unicon code. Particularly you
> would miss the class system, I think.
>
> The Image() function handles the same-structure-twice and circularity
> problems by generating labels for structures, which is what the built-in
> image() function does. The above would print something like this (as I
> recall):
>    L2:[ L1:['a', 'b'], L1, L2]
>
> -- Michael Glass
>    Valparaiso University
>
>
> On 03/10/2014 03:10 PM, Robert Heckendorn wrote:
>
>> Couple of nice solutions!  Educational , interesting, elegant.  Thanks!
>>
>>
>> Here is the actual problem:
>>     I want the write() and writes() funcitons to take arbitrary typed
>> objects and print something
>> reasonable.  So writeany() could take a list of lists for instance.  The
>> solutions so far do not
>> assume the components can be printed by writes.   What if this needs to
>> be a recursive application
>> of writeany for lists so each elem in the list is also printed with
>> writeany.   That gets in the way of
>> these two solutions for various reasons.   Anyone want to speculate on
>> an elegant method if the
>> function must invoke itself for each element until things writeable with
>> writes are found.
>>
>> cheers,
>>
>>
>>
>> ------------------------------------------------------------
>> ------------------
>> |
>> |     "People would rather believe than know."       -- E. O. Wilson
>> |
>> | Dr. Robert Heckendorn
>> | [email protected] <mailto:[email protected]>
>>
>> | http://marvin.cs.uidaho.edu/~heckendo
>> | Computer Science Dept, Univ. of Idaho, Moscow, Idaho, USA   83844-1010
>>
>>
>>
>> ------------------------------------------------------------
>> ------------------
>> Learn Graph Databases - Download FREE O'Reilly Book
>> "Graph Databases" is the definitive new guide to graph databases and their
>> applications. Written by three acclaimed leaders in the field,
>> this first edition is now available. Download your free book today!
>> http://p.sf.net/sfu/13534_NeoTech
>>
>>
>>
>> _______________________________________________
>> Unicon-group mailing list
>> [email protected]
>> https://lists.sourceforge.net/lists/listinfo/unicon-group
>>
>>
>


-- 
------------------------------------------------------------------------------
|
|     "People would rather believe than know."       -- E. O. Wilson
|
| Dr. Robert Heckendorn
| [email protected]
| http://marvin.cs.uidaho.edu/~heckendo
| Computer Science Dept, Univ. of Idaho, Moscow, Idaho, USA   83844-1010
------------------------------------------------------------------------------
Learn Graph Databases - Download FREE O'Reilly Book
"Graph Databases" is the definitive new guide to graph databases and their
applications. Written by three acclaimed leaders in the field,
this first edition is now available. Download your free book today!
http://p.sf.net/sfu/13534_NeoTech
_______________________________________________
Unicon-group mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/unicon-group

Reply via email to