[Tutor] help (stack are confusing me could someone help out with this simple program)

Magnus Lycka magnus@thinkware.se
Tue Oct 22 07:55:03 2002


At 20:39 2002-10-21 -0600, Dan Dud wrote:
>def x():
>    print x()

What's the purpose of this function? When you
call this function, the following happens:

Ok, we're in the x function, hm...what are we
going to do. Yes we should print the return value
from a function x called without parameters. So,
let us call x. Ok, we're in the x function, hm...
what are we going to do. Yes we should print the
return value from a function x called without
parameters. So, let us call x. Ok, we're in the x
function, hm...what are we going to do. Yes we
should print the return value from a function x
called without parameters. So, let us call x. Ok,
we're in the x function, hm...what are we going
to do. Yes we should print the return value from
a function x called without parameters. So, let
us call x...Ad infinitum... (or rather until the
stack is full...)

Besides calling itself recursively, it doesn't
do anything. It will never ever get to printing
anything. What did you think it would do?

Can you tell us what you want your program to do?

Further down in the code you compare the
functions x and y. Why do you want to do that?
The "value" of functions used in comparisions
is just their addresses in the RAM when you run
the program.

It seems to me that you haven't quite got the
hang of functions and variables. Perhaps you
should work through the python tutorial or
Alan Gaulds tutorial at
http://www.freenetpages.co.uk/hp/alan.gauld/

Feel free to return here with more questions,
but I think you have to step back a bit. You
seem to be slightly over your head now.


--=20
Magnus Lyck=E5, Thinkware AB
=C4lvans v=E4g 99, SE-907 50 UME=C5
tel: 070-582 80 65, fax: 070-612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se