Post Reply 
Change the way LOCAL variable declaration works.
06-10-2014, 02:34 PM
Post: #5
RE: Change the way LOCAL variable declaration works.
(06-10-2014 06:01 AM)cyrille de brĂ©bisson Wrote:  Hello,

Quote: [Kind of]What I am trying to do is take 'names' as input, declare local variables programatical based on these names, and then use the variables

Is that accurate?
If yes, then, sorry, but I can not think of any easy way to do it... As a mater of fact, very few comuter languages have such abilities!

One thing that pops in mind (might not work, but worth a try):

Get the list of variables that you are interested in.
Create a list with n elements (as many as you have variables).
Then REPLACE, in your original expression each of the variables names with 'list(n)' where n is the index in the list of the variable that you are replacing... and then it should work...

Now, please note that if you are mixing numerical and CAS stuff together, it will probably not work as numerica/CAS inverwork on variables is limited.

But this technique should work if you stay purely CAS or purely non CAS.
Take care of properly quoting the arguements that needs it.

Cyrille

My problem was: I wanted to declare LOCAL variables from an expression as an argument to my prog. totaly independent of waring what the vars. in the expression were. I just wanted give to the program an expressin and some values corresopnding to the variables as an array and the program would evaluate and/or substitute those values in the expressin. Depending on the number of rows in the array of values I would get list of numbers and/or new expressins with something substituted for variables if I wanted to. Of course the values would have to have an order that would correspond to the variables in alphabetical order, the program would take care for sorting the extrakted variable. All should happen without me woring what the variables and in what order they were in the expression and everything would happen in the scope of the program so at the end I would get the list of values/expressins and no garbage left outside of the program. To do that I needed to declare the extracted variables from the expressin as a LOCAL variables and that did not work because whenever I took a variable from the variables list and try to do it as LOCAL I was getting an error.

I wanted to suggest, in my post, to make the LOCAL declaratin more flexible so it would accept and declare as locals variables from some list witout an error ex. LOCAL vars(1), vars(2) etc. LOCAL accepts for example x or x={} etc why it can not accept for example vars(1) and take whatever vars(1) is as long as it evaluates to a variable. That should not be to difficult to impliment, I think.

I solved the problem using Han's explanation for creating CAS variables but they are stored as global vars but that is not a big problem because at the end I can purge them. The program I wrote works quite well and is olomost 98% what I wanted. I would also like to mention thet the command in HP Prime 'algvar' is not 100% perfect. It works as expected when I use 'algvar(z+x+y)' and gives [[z,x,y]] but when the expression is SIN(z)+y+x 'algvar(SIN(z)+y+x)' gives as variables [[SIN(z),y,x]] and that is not correct because SIN(z) is a funktion not a variable z is the variable.

Thank you Cirill for your time to answare my post, much appreciated.
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Change the way LOCAL variable declaration works. - John P - 06-10-2014 02:34 PM



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