Assigned variables and batch purge (CAS utility functions) - dae - 10-17-2019 04:17 PM
Here are a three CAS utility functions. Two of them, varslist1() and varslist2(), identify assigned variables, showing type and value. The third can be used to batch purge single-character lower-case variables.
A. varslist1() identifies a-z variables which have been assigned values. It shows the variable type and the value.
Code:
#cas
// Identifies lower-case one-letter variables
// such as "a", "b", etc.
// Must run from CAS side
// It's a function, so it needs empty "()"s, i.e., varslist1()
varslist1():=
BEGIN
local mylist, myindex;
mylist := "abcdfghjklmnopqrstuvwxyz";
print("assigned lower-case one-letter vars");
for myindex from 1 to length(mylist) do
//DOM_IDENT = 6
if type(expr(mylist[myindex])) != 6 then
print(mylist[myindex] + ": " +
type(expr(mylist[myindex])));
print(expr(mylist[myindex]));
end;
end;
print("**end of list**");
END;
#end
B. varslist2() is not limited to one-character variables. You can include any variable names by adding them to the mylist variable. Place the variable name in quotes and separate with a comma. Your variables can be placed anywhere in the list.
Code:
#cas
// This version allows for any-length variables
// just add them to mylist, inside double quotes, separated by comma
// Must run from CAS side
// It's a function, so it needs empty "()"s, i.e., varslist2()
varslist2():=
BEGIN
local mylist, myindex;
//this example has added x1, x2, E1, and X to mylist
//modify mylist as you see fit
mylist := ["a","b","c","d","f","g","h","j","k","l",
"m","n","o","p","q","r","s","t","u","v",
"w","x","y","z",
"x1","x2","E1","X"]; //edit this variable
print("varslist2: mylist vars assigned values");
for myindex from 1 to length(mylist) do
//DOM_IDENT = 6
if type(expr(mylist[myindex])) != 6 then
print(mylist[myindex] + ": " +
type(expr(mylist[myindex])));
print(expr(mylist[myindex]));
end;
end;
print("**end of list**");
END;
#end
C. purgeaz() clears the values from small a to small z (e and i are reserved and ignored)
Code:
#cas
// purgeaz(): purge all single small-letter variables
// excludes e and i, which are reserved anyway
// Run from CAS side
// it's a CAS function call, i.e. purgeaz()
purgeaz():=
BEGIN
purge([a,b,c,d,f,g,h,j,
k,l,m,n,o,p,q,r,s,t,
u,v,w,x,y,z]);
return("Vars a to z have been purged");
END;
#end
|