[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: [Maxima] Bug in 'for', Maxima, Debian ?



On Wednesday 07 of July 2010 19:46:38 you wrote:
> Zbigniew Komarnicki escribió:
> > Hello,
> >
> > I try to write fuction that return a list of number in range [a,b] with
> > step k, but first i try in command window this code:
> >
> > /* This work in command window without variables */
> > kill(all);
> > m:[];
> > for i:0 step -3 thru 10 do (m:append(m, [i]), display(i));
> > display(m);
> >
> > Here is OK
>
> If you want to reach 10, shouldn't step be a positive number?

Thank you.

No, I try exactly from 0 to 10 with step -3. I know that it should be empty 
list (empty matrix I got in octave, see below)

Form 0 to 10 with step 3 it work excellent - there is no problem. 

(%i1) m:[]$
(%i2) for i:0 step 3 thru 10 do (m:append(m, [i]), display(i))$
         i = 0
         i = 3
         i = 6
         i = 9

(%i4) display(m)$
        m = [0, 3, 6, 9]

The problem is when I go with 0 to 10 with -3 or in general when:
a < b and k is negative number.   


In Octave I write something like:
From 0 to 10 with step -3 I got empty matrix in octave:

octave:1> 0:-3:10
ans = [](1x0)

I got empty matrix it is correct. 

From 0 to 10 with step 3 I got as expected

octave:2> 0:3:10
ans =
    0    3    6    9

I got results as expected.

The problem in Maxima is when we use variables:
a:0;
b:10;
k:-3;
m:[];
and write the code:
for i:a step k thru b do (m:append(m, [i]), display(i))$

This loop shouldn't execute, but this loop go forever (!!!) writing: i=0, 
i=-3, i=-6, ..., i=infinity, but when I write this same code with numbers in 
the loop, it work as expected:

m:[];
for i:0 step -3 thru 10 do (m:append(m, [i]), display(i))$
display(m)$
     m = []

and the result is empty list m=[].


> --
> Mario


Reply to: