Post Reply 
CAS programs, order of LOCAL variables?
12-10-2016, 09:13 PM
Post: #1
CAS programs, order of LOCAL variables?
Something strange is happening depending on the order of LOCAL declarations in CAS programs. For example,

#cas
TEST(k):=
BEGIN
LOCAL a:=1,j

FOR j FROM 2 to k DO
IF odd(j) THEN
a:=a+1/(2*j-1);
ELSE
a:=a-1/(2*j-1);
END;
END;
RETURN a;
END;
#end

is unstable, and returns different results for the same input, and j and a get written into the CAS Vars catalog.

However, changing the LOCAL declaration works, e.g.
...
LOCAL j,a:=1
...

runs OK.

So, if a variable has been declared and defined a value, should a subsequent variable not appear on the same LOCAL statement?

BTW, this doesn't seem to be a problem with LOCAL statements in Home programs.
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
CAS programs, order of LOCAL variables? - Helge Gabert - 12-10-2016 09:13 PM



User(s) browsing this thread: 1 Guest(s)