Post Reply 
How do you assign a global var in a CAS function?
11-05-2017, 11:18 PM
Post: #1
How do you assign a global var in a CAS function?
e.g., if you use EXPORT as below...

#cas
TEST(l):=
BEGIN
EXPORT MMM:=256;
RETURN l[3];
END;
#end

...it compiles OK, but when you try to run TEST(L1), it'll give a bad argument error.
However, if you comment out the EXPORT statement, it'll work fine.

How do you create a global variable in a CAS function if EXPORT doesn't work?

Thanks
-Donald
Find all posts by this user
Quote this message in a reply
11-05-2017, 11:27 PM
Post: #2
RE: How do you assign a global var in a CAS function?
I did figure this out...

EXPORT MMM:=256;

#cas
TEST(l):=
BEGIN
RETURN MMM*l[3];
END
#end

...but MMM is a Home variable when done this way.
Let's say I want to create a global CAS list, which can be indexed using []. How do I do that from a CAS program?
Find all posts by this user
Quote this message in a reply
11-05-2017, 11:58 PM (This post was last modified: 11-06-2017 12:14 AM by webmasterpdx.)
Post: #3
RE: How do you assign a global var in a CAS function?
Never mind! I think I got it figured....

If you do the following...

#cas
TEST(l):=
BEGIN
m:={5,4,3,2,1};
RETURN l[3]*m[2];
END
#end

m is now a global CAS variable of type list.

Also, if the program was a Home program (defined with EXPORT), then assigning m the same way (not declared as LOCAL), it would be a Home variable of type List...and global. i.e. EXPORT is only needed for global variable definition if outside a program definition.
Find all posts by this user
Quote this message in a reply
11-06-2017, 08:20 PM (This post was last modified: 11-06-2017 08:22 PM by salvomic.)
Post: #4
RE: How do you assign a global var in a CAS function?
(11-05-2017 11:27 PM)webmasterpdx Wrote:  I did figure this out...

EXPORT MMM:=256;

#cas
TEST(l):=
BEGIN
RETURN MMM*l[3];
END
#end

...but MMM is a Home variable when done this way.
Let's say I want to create a global CAS list, which can be indexed using []. How do I do that from a CAS program?

Export is to use first of the #cas #end or BEGIN END; block, with default values, like:
Code:
export MMM:=[[0,0],[0,0]];

In another part of the program you must use STO (or sto) to store a value in the var exported, like:
Code:
sto({varrow, varcol}, MMM);
not return, that you can use for other purpose...
When you store something, you can also read the variable in another part of the program (or other program)...

Is this your goal?

Salvo

∫aL√0mic (IT9CLU) :: HP Prime 50g 41CX 71b 42s 39s 35s 12C 15C - DM42, DM41X - WP34s Prime Soft. Lib
Visit this user's website Find all posts by this user
Quote this message in a reply
11-06-2017, 08:33 PM
Post: #5
RE: How do you assign a global var in a CAS function?
My goal was just figuring out when variables are cas vars vs home vars. e.g. just assigning a var in a cas program (that isn't declared as local) will make it global, and if assigned in a cas program, it will be a cas variable. If it's a list for example, you'll need to use [] to index it instead of (). i.e. It makes a difference if it's a cas vs a home variable, even if the same type.
Find all posts by this user
Quote this message in a reply
11-06-2017, 10:01 PM
Post: #6
RE: How do you assign a global var in a CAS function?
Donald,
probably you have already read this tutorial by Han.
There is a lot of things to know about CAS programming.
I hope you could find help in there.

Salvo

∫aL√0mic (IT9CLU) :: HP Prime 50g 41CX 71b 42s 39s 35s 12C 15C - DM42, DM41X - WP34s Prime Soft. Lib
Visit this user's website Find all posts by this user
Quote this message in a reply
11-07-2017, 06:47 AM (This post was last modified: 11-07-2017 06:52 AM by webmasterpdx.)
Post: #7
RE: How do you assign a global var in a CAS function?
That article says that in CAS programs variable initialization must be done seperately from declaration.
...as in:

local c;
c:=5;

However, I just tried initialization on the same line as in:

local c:=5;

...and it worked.

So....is this still the case or is it OK to initialize in the same line as declaration with the latest firmware?
Let me know and I'll edit the article to remove that....

???
Thx
-Donald
Find all posts by this user
Quote this message in a reply
11-07-2017, 07:10 AM
Post: #8
RE: How do you assign a global var in a CAS function?
You can assign variables in a local statement, but you must take care of priorities, for example
Code:
local a:=1,c:=3;
will assign a to 1,3 like
Code:
local a:=(1,c:=3);
unlike
Code:
local (a:=1),(c:=3);
That's why it is recommended to assign local variables outside of the local declaration.
In a CAS program, non declared variables are global, if they already exist in Home (i.e. you made an EXPORT before) then they are HOME variables, otherwise they are global CAS variables.
Find all posts by this user
Quote this message in a reply
11-07-2017, 07:44 AM
Post: #9
RE: How do you assign a global var in a CAS function?
Thanks Parisse.....that clears it up.
-Donald
Find all posts by this user
Quote this message in a reply
Post Reply 




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