Re: [Tutor] Misc question about scoping

2010-06-05 Thread Tino Dai
On Fri, Jun 4, 2010 at 8:24 PM, Alan Gauld wrote:

> "Hugo Arts"  wrote
>
>
>  [1] http://mitpress.mit.edu/sicp/
>> [2]
>> http://groups.csail.mit.edu/mac/classes/6.001/abelson-sussman-lectures/
>>
>>
> And I'd add the superb How to Design Programs:
>
> http://www.htdp.org/
>
> It teaches Scheme programming using a recipe approach
> that creates a standard stricture for a function. It then extends
> that structure as the examples build in complexity but always
> keeping the basic theme.
>
> This book and SICP are two of the best for making you rethink all
> you thought you knew about program structure and design!
>

How about the ANSI Lisp by Paul Graham. Any options negative or positive?


>
> If you really want to bend your brain in Lisp (Scheme) try
> The Little Schemer and its follow up the Seasoned Schemer
> It took me 3 attempts to really get to grips with the first and
> I'm on my second attempt at the second!
>

Is that linked to the Little Lisper somehow?


>
> What all these books will do is give you a rational approach
> to problem solving for programming that will often work when
> more 'conventional' approaches don't. The performance of the
> resulting code may not be optimal but it will often give you
> the key breakthrough that you can then rewrite more
> conventionally into good and fast code. It also often leads to
> much more elegant solutions. Good for when you have
> something that works but looks a mess... rethink it for
> Lisp and see what's different.
>
>
> --
> Alan Gauld
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
>
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] treeTraversal, nested return?

2010-06-05 Thread Matthew Wood
On Fri, Jun 4, 2010 at 7:40 PM,  wrote:

> Matthew,
>
> sorry for responding to you instead of the list
>
>
> Thanks for trying to tutor the dunderheaded. It is exactly the general
> solution I wish to learn. But how, in the context of my treeTraversal
> function, does one "keep track of the depth you're at"? Tabs are all very
> well, but what I want is truly a nested structure, and as you point out in
>  that's not what I was showing in my html (though deprecated,
> browsers still render lists like the one I showed).
>
> The simplest and most graphic example would be a nested list of lists, but
> for the life of me I can't work out how to generate that in this context.
>
> Jon
>
>
>
> On Fri, 4 Jun 2010, Matthew Wood wrote:
>
>  In general, there's 2 solutions to your "unflattening" problem.
>> A) The general solution: Keep track of the depth you're at, and add
>>
> tabs/spaces ('\t' * depth) as necessary.
>
>
>
>

Spir's example demonstrates the idiom.  Watch the "level" variable.  During
our function, it gets incremented, and then passed into the next recursive
call.  Thus, each call to the recursive function is passing along the
appropriate tab depth level.

Good luck yo.  Recursion is one of those concepts that just clicks one day.
 At least that's how it is for me.

I'll attempt to provide a pseudo pseudo code description:



def recursive_func(data, indent_level):

if is_printable_node(data):
print '\t' * indent_level + string_format(data)

else:
# now we know it's not a node, so it must be a child list.
for sub_data in data:
recursive_func(sub_data, indent_level + 1)


Again, watch the indent_level variable.


--

I enjoy haiku
but sometimes they don't make sense;
refrigerator?
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Misc question about scoping

2010-06-05 Thread ALAN GAULD

>
>>>If you really want to bend your brain in Lisp (Scheme) try
The Little Schemer and its follow up the Seasoned Schemer
>>
>
>Is that linked to the Little Lisper somehow?
>Yes, its the second edition ported to Scheme.
In fact I used the Little Lisper then moved to the Seasoned Schemer.
There is a third volume, The Reasoned Schemer, which I also have 
but I haven't even opened it yet...


Alan Gauld

Author of the Learn to Program web site

http://www.alan-g.me.uk/
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor