Question:
Do recursive functions require arguments?
Keira
2013-04-21 11:02:02 UTC
Also what's a os se, parameter, smart compiler, stack frame in recursive and how do you pass one function as an argument to another function?
Three answers:
Russel
2013-04-22 00:14:23 UTC
--------

os se ?

--------

I'm not sure what os se is but as a guess I think os could be operating system. For example Python has a module in the standard library called os which contains interfaces for the operating system. I've only ever seen se refer to "special edition" in general but I can't say for sure what "os se" is.



http://docs.python.org/2/library/os.html



--------------

parameter

--------------

http://en.wikipedia.org/wiki/Parameter_%28computer_science%29

A parameter is essentially a variable. To understand and remember what a parameter is follow with me.



x = 1



Here x is a variable and 1 is a value of type int, that's being assigned to the x variable.

Pretty straight forward right? The value is the data, the variable is the container for the data.



def a(x):

....print x



a(1)



Here we have a "function definition" in the first two lines. The last line is a "call" to the function.

In the first line of the function definition you have whats called the function header. Functions can be thought of as small boxes with input and output. The input is in the function header in the part enclosed by parenthesis.



Ok so you might think of the x in the function header as a variable and the 1 in the last line as a value being assigned to x when the function is called. You wouldn't be far off, but with functions we use a slightly different terminology. We call the x a parameter and the 1 an argument. Many people actually don't know the difference between a parameter and an argument.



Arguments are passed to parameters ; values is assigned to variables.



Take note though that when you actually use the parameter x in the "body" of the function, it's no longer a parameter, it's just another local variable and can be changed.



--------------------

smart compiler

---------------------

In computer science you have compilers, optimizing compilers and then you have smart compilers.

A compiler is just a program that takes your source code and converts it into executable code, 1s and 0s.



An optimizing compiler doesn't just convert your code, it optimizes it using a number of techniques.



A smart compiler doesn't just optimize your code using a set of standard techniques, it tries out the different techniques to see what works best because optimization is not so straight forward and some optimizations may even make the program slower. So a smart compiler can "do experiments" with your code.



http://www.ai.mit.edu/projects/reinventing_computing/papers/theses/pshuang/meng/node7.html



----------------

stack frame

----------------

Firstly what is a stack.

http://en.wikipedia.org/wiki/Call_stack

Then a stack frame is a call to a function/subroutine that has not yet terminated with a return statement. In other words a call that is still active. A recursive stack frame is a call in a recursive stack that has not yet terminated.



----------------

Passing a function as an argument

----------------

First, in Python you can pass the return value of a function as an argument to another function like this.



def a():

....return 1



def b(x):

....print x



b(a())



>>> 1



What will happen is a() will run and it will return 1 so that last line effectively becomes



b(1)



which is passed as an argument to the x parameter in b.



Second, you can pass a function itself as an argument to another function. Most beginners will confuse these two cases which is why I first explained the first case of passing the return value of a "function call" to another function and then the second case of passing the function itself.



In the second case you pass the function name not a call to the function.



def a():

....print 1



def b(x):

....x()



b(a)



>>> 1



Just look at that carefully until it clicks.



Rest of the answer is here:

http://pastebin.com/33mTZak2
David W
2013-04-21 14:34:48 UTC
No, it's entirely possible to write a (non-infinite, I assume you mean) recursive call without a parameter. If you based your function exit on a variable who's scope was beyond that of the function call, for example...
?
2016-12-15 18:47:02 UTC
*i : dereferences pointer i. if i is a pointer form it returns the information it factors to. in any different case it supplies an errors. *(&i) : dereferences a connection with i. that's fairly the comparable as i yet with an indirection, returns the linked fee of i. int *i : decrales a pointer to int i. occasion: int j; int *i = &j; right here statements are real: *i == j *(&i) == i


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Continue reading on narkive:
Loading...