# [Maxima] Q about arguments scoping in function definition

Richard Fateman fateman at cs.berkeley.edu
Mon Oct 8 10:40:40 CDT 2007

```I disagree [with Robert] (at least in the context of dynamic scope).
..
You write a program that does this:

F(x):= sin(x)+cos(x)

G(x):=F(F(x))

It is pretty clear what this does.

Now someone, unknown to you, wants to use G(x), but is actually unaware of
the insides of G.

He writes a program like this.

H(F):= G(F+1)^2

Totally by accident, he has broken your definition of G.

The current situation is pretty clear.  Use apply(f,[arg1,arg2, ...]) to be
safe.
RJF

> -----Original Message-----
> From: maxima-bounces at math.utexas.edu
> [mailto:maxima-bounces at math.utexas.edu] On Behalf Of Robert Dodier
> Sent: Monday, October 08, 2007 7:46 AM
> To: Stavros Macrakis
> Cc: Andrey Siver; maxima at math.utexas.edu
> Subject: Re: [Maxima] Q about arguments scoping in function definition
>
> On 10/8/07, Stavros Macrakis <macrakis at alum.mit.edu> wrote:
>
> > In the Maxima language, the f in f(x) is evaluated as follows:
> >   1) If it is a lambda expression, apply it.
> >   2) If it is a symbol, then
> >       a) if it is a built-in function, apply it
> >       a) if it has a ":=" value, substitute that and go back to (1)
> >       b) if it has a ":" value or binding, substitute that
> and go back to (1)
> >   3) Consider f to be a formal function, and just simplify
> the expression f(x).
>
> It seems like results would be more predictable if (2b) were moved
> ahead of the other two (2a) items. As it stands, if a symbol is bound
> to something other than itself, sometimes that binding is used in a
> function call and sometimes it isn't.
>
> It seems unlikely that there is code which depends on the existing
> policy, as stated above, so it might be safe to modify it.
> Of course we would want to test such a change.
>
> best
>
> Robert
> _______________________________________________
> Maxima mailing list
> Maxima at math.utexas.edu
> http://www.math.utexas.edu/mailman/listinfo/maxima
>
```