On 01/08/2014 10:11 PM, Keith Winston wrote:
On Wed, Jan 8, 2014 at 3:42 PM, Emile van Sebille <em...@fenx.com> wrote:


Without seeing your code it's hard to be specific, but it's obvious you'll
need to rethink your approach.  :)



Yes, it's clear I need to do the bulk of it without recusion, I haven't
really thought about how to do that. I may or may not ever get around to
doing it, since this was primarily an exercise in recursion, for me...
Thanks for your thoughts.

Funny and useful exercise in recursion: write a func that builds str and repr expressions of any object, whatever its attributes, inductively. Eg with

        obj.__repr__() = Type(attr1, attr2...)          # as in code
        obj.__str__()  = {id1:attr1 id2:attr2...}       # nicer

Denis

PS: Don't knwo why it's not builtin, would be very useful for debugging, testing, any kind of programmer feedback. Guess it has to do with cycles, but there are ways to do that; and python manages cycles in list expressions:

spir@ospir:~$ python3
Python 3.3.1 (default, Sep 25 2013, 19:29:01)
[GCC 4.7.3] on linux
Type "help", "copyright", "credits" or "license" for more information.
l1 = [1]
l2 = [1, l1]
l1.extend([l2,l1])
l1
[1, [1, [...]], [...]]
l2
[1, [1, [...], [...]]]
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Reply via email to