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: Stavros Macrakis
Date: Wed, 26 Aug 2009 11:21:01 -0400
On Wed, Aug 26, 2009 at 10:52 AM, Josephy, Norman <NJOSEPHY at bentley.edu>wrote:
> ...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.
>
You are mixing up the notion of "binding" with the notion of "looking up".
In your example, the variable f is indeed bound locally in g(f).
But the semantics of f(3) are that the *function binding* of f is looked up
before the local *value binding* of f.
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.
>
It binds the dummy variable, but in the expression f(3), f is a reference to
the *function value* of f if there is one, and only if it is not is it the
value binding.
Does that make it any clearer?
-s
> 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
>
> _______________________________________________
> Maxima mailing list
> Maxima at math.utexas.edu
> http://www.math.utexas.edu/mailman/listinfo/maxima
>