Newbie Question: Are arguments in a function definition bound when function is called?
Subject: Newbie Question: Are arguments in a function definition bound when function is called?
From: Josephy, Norman
Date: Wed, 26 Aug 2009 10:52:00 -0400
Hello:
Thank you for your quick response.
I have looked at some of the lisp-1 vs. lisp-2 postings.
My lack of understanding is quite profound.
Am I correct in the following:
g(f) := f(3);
f(x) := x^3;
g(sin);
My questions relate to how and when the arguments of the function g are bound.
To my suprise, for the function call g(sin), the variable f in the body of g is not automatically
bound to the calling value sin, but the search for the value of
f seems to start with (possibly) looking in the function slot of f, which happens to be filled with
some global definition. The calling value sin is ignored.
My (clearly wrong) expectation was that the calling function argument (the sin in g(sin))
determined the value of the dummy variable f in the definition of g, irrespective of any
definition of f occuring either before or after the definition of g.
My confusion is why g(sin) is sometimes not sin(3). My expectation is that the definition of
g sets up an environment that will bind f to whatever is 'sent' to the function g when g is called.
It seems that the binding to f occurs when f(x) := x^3 is defined, rather than when g is called.
And the choice of what to bind to f depends upon whether the current definition of f is a value or a function.
I apologize if I am missing something obvious or fundamental.
Any additional pointers in any of the Maxima documentation or tutorials would be appreciated.
Thank you again,
Norm