Post Reply 
Create a list of undefined user vars?
01-27-2016, 04:13 PM (This post was last modified: 01-27-2016 04:15 PM by Didier Lachieze.)
Post: #13
RE: Create a list of undefined user vars?
(01-27-2016 12:27 PM)DrD Wrote:  Using a list of undefined variable names, created and maintained without programmatic influence, is my specific objective. It's kind of like a database list, I guess. I'll try using the HVars approach next. That's a good idea, and one I haven't tried. There's more than one way to "skin" a prime - at least if you're using the EMU version!

Thanks (again), Cyrille!

-Dale-

I've played a bit with these different ideas and so here is a version of your test program where a list of undefined variables names is used to drive the INPUT statement and to retrieve the values:

Code:
EXPORT test()
BEGIN
  LOCAL j,l,s,v;
  
  //variables set-up
  v:={"dogs", "cats"};   //list of your undefined variables, replace with whatever list you want

  FOR j FROM 1 TO SIZE(v) DO IFTE(POS(HVars,v(j)),DelHVars(v(j)),0); END;  //ensure variables dogs & cats don't exist
  s:="L1:="+REPLACE(STRING(v),"""","'");  CAS(s);  // !!CREATE L1 IN CAS FIRST!!  ==> L1:={'dogs', 'cats'};
  FOR j FROM 1 TO SIZE(v) DO HVars(v(j)):=0; END;   //create variables dogs & cats for the INPUT statement, assuming that they are reals
  
  //Input statement
  EXPR("INPUT("+string(L1)+")");
  l:=EVAL(L1);    // get contents of {dogs,cats} 

  //Variable clean-up
  FOR j FROM 1 TO SIZE(v) DO DelHVars(v(j)); END;    //delete variables dogs & cats
  L1:={};    //clear L1

  return l;    //returns contents of {dogs,cats} ==> {5,4}
END;
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Create a list of undefined user vars? - Didier Lachieze - 01-27-2016 04:13 PM



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