Global vars
Modérateur : xcasadmin
-
- Messages : 603
- Inscription : sam. févr. 04, 2017 11:34 pm
- Localisation : Colombia
- Contact :
Global vars
Hi, how can I save global variables, but when I run a program call again, these again do not lose their content
Thanks
Thanks
Re: Global vars
I don't understand what you mean.
-
- Messages : 603
- Inscription : sam. févr. 04, 2017 11:34 pm
- Localisation : Colombia
- Contact :
Re: Global vars
solved by putting x: = 0 before the definition of the function.
but the compiler should detect that the x variable has been defined previously and not throw the warning message Warning: x, declared as global variable(s)
// Parsing f
// Warning: x, declared as global variable(s) ...
// compiling f
f() [enter] returns 1
f() [enter] returns 2
f() [enter] returns 3
now// Parsing f1
// Warning: y, declared as global variable(s). If symbolic variables are required, declare them as local and run purge
// compiling f1
f1() [enter]
"y: recursive definition Error: Bad Argument Value"
the trick for the variable to be symbolic is to add the following statement
local y; purge(y);
f1() [enter] y+1
but to be more explicit the code, I think that a new command is necessary Symbs id0,id2,...idn it's a great idea?
Symbs y; replaces local y; purge(y);
f1() [enter] y+1
f();f1();f2(); [enter]
1, y+1, x+1
f();f1();f2(); [enter]
2, y+1, x+1
f();f1();f2(); [enter]
3, y+1, x+1
but the compiler should detect that the x variable has been defined previously and not throw the warning message Warning: x, declared as global variable(s)
Code : Tout sélectionner
x:=0;
f():={
x:=x+1; // global
print(x);
}:;
// Warning: x, declared as global variable(s) ...
// compiling f
f() [enter] returns 1
f() [enter] returns 2
f() [enter] returns 3
now
Code : Tout sélectionner
f1():={
y:=y+1;
print(y);
}:;
// Warning: y, declared as global variable(s). If symbolic variables are required, declare them as local and run purge
// compiling f1
f1() [enter]
"y: recursive definition Error: Bad Argument Value"
the trick for the variable to be symbolic is to add the following statement
local y; purge(y);
Code : Tout sélectionner
f1():={
local y; purge(y);
y:=y+1;
print(y);
}:;
but to be more explicit the code, I think that a new command is necessary Symbs id0,id2,...idn it's a great idea?

Symbs y; replaces local y; purge(y);
Code : Tout sélectionner
f1():={
Symbs y;
y:=y+1;
print(y);
}:;
Code : Tout sélectionner
x:=0; // global
f():={
x:=x+1;
print(x);
}:;
f1():={
local y; purge(y); // Symbs y
y:=y+1;
print(y);
}:;
f2():={
local x; purge(x); // Symbs x
x:=x+1;
print(x);
}:;
1, y+1, x+1
f();f1();f2(); [enter]
2, y+1, x+1
f();f1();f2(); [enter]
3, y+1, x+1
Re: Global vars
First the compiler should not check that x is assigned, because that may change later, second it is essential to throw a warning message, because functions should not use global variables, only local variables. Global variables are tolerable for symbolic variables, but it's better to use a symbolic local variable, as explained in the warning. If you really want a global variable, you can still declare it as global.compsystems a écrit :solved by putting x: = 0 before the definition of the function.
but the compiler should detect that the x variable has been defined previously and not throw the warning message Warning: x, declared as global variable(s)
-
- Messages : 603
- Inscription : sam. févr. 04, 2017 11:34 pm
- Localisation : Colombia
- Contact :
Re: Global vars
ok,
What do you think of an alternative command
local y; purge(y);
as
symbs y;
local y,z; purge(y,z); as symbs y,z;
other CAS as the matlab symbolic toolbox follows this syntax
What do you think of an alternative command
local y; purge(y);
as
symbs y;
local y,z; purge(y,z); as symbs y,z;
other CAS as the matlab symbolic toolbox follows this syntax
Re: Global vars
Don't forget that it's easy to make suggestions, but it's not as easy to implement them and I have limited ressources, I can not spend one or 2 hours per day implementing all your suggestions. So please try to sort your suggestions, and send only important ones, for example replacing local y; purge(y); by whatever y; is not very important since the functionnality is already available. The same applies for cosmetic UI changes.
-
- Messages : 1139
- Inscription : dim. mai 20, 2007 7:09 am
- Localisation : Paris
- Contact :
Re: Global vars
NB, there are several way to do this.
for instance in giac simple quotes means the unevaluated form of the object (it is not the same as double quotes) so I often do this:
another way to do this:
for instance in giac simple quotes means the unevaluated form of the object (it is not the same as double quotes) so I often do this:
Code : Tout sélectionner
f1():={
local y:='y';
y:=y+1;
print(y);
}:;
Code : Tout sélectionner
f1():={
local y; purge(y);
y:=y+1;
print(y);
}:;