Post Reply 
Assigned variables and batch purge (CAS utility functions)
10-17-2019, 09:17 PM (This post was last modified: 11-08-2019 06:01 AM by dae.)
Post: #1
Assigned variables and batch purge (CAS utility functions)
Here are a three CAS utility functions. Two of them, varslistaz() and varslist2(), identify assigned variables, showing type and value. The third can be used to batch purge single-character lower-case variables.

When a-z variables have previously assigned values, they will not work correctly as symbols in expressions or functions. They need to be purged.
varslistaz() will show you which a-z variables have been assigned. If you want to clear them all (but no others) run purgeaz().
varslist2() is designed for you to edit what you want to view. If you frequently use values such as e1, e2, e3, etc., you can add them to the list to see whether they have assigned values.

A. varslistaz() 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() 

varslistaz():=
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


Attached File(s) Thumbnail(s)
   
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
Assigned variables and batch purge (CAS utility functions) - dae - 10-17-2019 09:17 PM



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