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 07:49:12 -0400
Hi:
I am confused about the following behaviour and would appreciate if someone could explain it to me.
I am using Maxima 5.19.1 and the bundled wxMaxima 0.8.3a under
Microsoft Windows XP x64 edition Version 2003 Service Pack 2.
I am going to have my students use Maxima for the first time in my calculus class.
I wish to avoid situations where the mechanism for binding an argument in
a function definition does not bind to the value passed to it from a function call.
kill(all);
/* Define a function that is passed a function name */
g(f,x) := f(x);
/* Test the function definition */
g(sin,5); /* --> sin(5) o.k. */
/* Bind the name used in the function definition to a specific function */
f : lambda([x],x^2);
/* Verify that the function g still 'works' as before */
g(f,x); /* --> x^2 o.k. */
g(sin,5); /* --> sin(5) o.k. */
/* Repeat the above using the alternative notation for function definition */
kill(all);
g(f,x) := f(x);
f(x) := x^2;
g(f,x); /* --> x^2 o.k. */
g(sin,5); /* --> 25 ??? */
It seems that the argument f in the definition of g gets bound to
the definition x^2.
I was 'hoping' that the arguments in a function definition would
always get bound to whatever arguments are passed to it from the calling function.
Thank you in advance.
Norman