strangeness: constructing subscripted functions



On Mon, Jul 14, 2008 at 11:55 PM, Robert Dodier <robert.dodier at gmail.com>
wrote:

> foo [x] (y) := x * length (y);
> foo [3];
>  => error: length called on atomic symbol y
> Instead maybe I'd hope to see lambda([y], 3 * length(y)) .
>
> To construct the lambda expression for foo[3], Maxima evaluates
> (via MEVAL) the right-hand side. So length is called but barfs since
> y is not yet bound to anything.
>
> I'll take this opportunity to propose that Maxima should be less
> aggressive about evaluating the right-hand side. How about calling
> MEVALATOMS instead of MEVAL. Yes / no / maybe ??
>

Memo'izing (saving results) is the whole raison d'etre of f[](), and not
doubly evaluating the RHS defeats that purpose. Of course, this leads to the
problems with double evaluation; not only the one above, but also:

a0:'a1$ a1:'a2$
f():=a0$    f()    =>    a1
f[1]():=a0$    f[1]()    =>    a1
f[i]():=a0$    f[2]()    =>    a2

(which would not be fixed by the proposed change).

If you don't want the double evaluation, why not just use ordinary functions
foo(x,y):=... or the fully memoizing function foo[x,y]:=...?

I don't particularly like this notation, but there is actually some real
functionality behind it.  If we want a cleaner notation, let's let f[i](x)
be just syntactic sugar for f(i,x) and define some other notation for
memo'izing.

             -s