write
cands: delete(i,cands),
because delete does not change cands. It makes a new list with the
specified alterations.
This kind of non-destructive programming (part of "functional
programming") has many advantages
(and a few disadvantages).
RJF
Robyn Dawn Hannigan wrote:
> Dear Maxima Developers,
>
> As another new user facing the same problem over the usage of the delete
> operator, in a list, i here post the following trivial example of its
> attempted use.
>
> In the construction of a simple Sieve of Eurastothenes for finding
> primes below an integer x, one approach is to construct a list of
> possible primes, then delete obvious non-primes. Here we go with the
> problenm then.
> (%i54) allprimes(x) := block(
> [
> max:x,
> smax:x^(1/2),
> cands:[]
> ],
> cands:makelist(x,x,1,max),
> for i:1 while i < smax do block(
> print(i),
> print(cands),
> print(args(cands)),
> delete(i,cands),
> print(cands)
> )
> )$
>
> (%i56) allprimes(10);
> 1
> [1,2,3,4,5,6,7,8,9,10]
> [1,2,3,4,5,6,7,8,9,10]
> [1,2,3,4,5,6,7,8,9,10]
> 2
> [1,2,3,4,5,6,7,8,9,10]
> [1,2,3,4,5,6,7,8,9,10]
> [1,2,3,4,5,6,7,8,9,10]
> 3
> [1,2,3,4,5,6,7,8,9,10]
> [1,2,3,4,5,6,7,8,9,10]
> [1,2,3,4,5,6,7,8,9,10]
> (%o56) done
>
> What i am trying to do is delete the value i, which in each iteration
> of the for is bound to an integer, which value one may see printed in
> the output.
>
> What am i missing?
>
>
> _______________________________________________
> Maxima mailing list
> Maxima at math.utexas.edu
> http://www.math.utexas.edu/mailman/listinfo/maxima
>