making for-loops more general. Was: Re: New version of makelist
Subject: making for-loops more general. Was: Re: New version of makelist
From: Richard Fateman
Date: Sun, 25 Apr 2010 21:17:05 -0700
Richard Fateman wrote:
> I added to the file mdo.lisp, referred to earlier the treatment of
> sets. Now
>
> for i in [a,b] collect f(i)
>
> returns
> [f[a],f[b]]
>
> The display program in the command-line version of maxima displays
> this new form of "do" properly.
> wxmaxima displays h(x):=for i in x collect f(i) using
> "mdoin-collect" instead of for ... collect.
>
> RJF.
As long as I was at it, I added to the file mdo.lisp the additional
grammatical and semantic routines to allow
for i:1 thru 10 summing f(i);
and also
for i in L summing f(i);
This should make it perfectly clear what is being added, and that it is
in fact being added. This
is not entirely clear if one writes sum(i , i,1,10). Is it being
simplified first? What about
h(k):=i^2,
sum(h(k),i,1,10). Is h(k) evaluated to i^2 or not...
It is also perfectly clear that for i:1 thru n summing f(i) is NOT
legitimate if n is just a "symbol".
I notice that the for-loop stuff does NOT permit the index to be (say)
x[k]. Is this really
useful? Indeed, the for-loop index is locally bound, and
block([i:aha], for i:1 thru 10 do i, print(i))
prints aha, not 10 or 11. ( I think FORTRAN would return 11 in similar
circumstances).
As for why I used "summing" rather than just "sum" ... it turns out
that making "sum" a keyword in
the context of "for ...." makes
sum(i,i,1,10) syntactically illegal.
Are there any problems with this?
Is anyone (else) sufficiently interested and capable of put the pieces in
this file into the source tree?
RJF