[Scilab-users] global constant definition for module
    Samuel Gougeon 
    sgougeon at free.fr
       
    Fri Mar  4 23:33:46 CET 2016
    
    
  
Le 02/03/2016 12:24, David Chèze a écrit :
> Hi all,
>
> I would like to define a variable in a user module in such a way that this
> constant would be available for all functions (also out of the module) as a
> "hidden(you don't need to see it inbrowsvar), protected (should not be
> possible to clear it, even with clearglobal )" global variable as soon the
> module is loaded: do you have suggestions how to do it within scilab?
There is still no actual solution to protect variables against clear.
But you may do the following:
// Save that in set_constantes.sci and build a library with it, thanks 
to genlib(), say constantes_lib
function  set_constantes()
     L0  =  "";  L0  =  who("local")  
     c0  =  299792458
     avog  =  6.022045e23
     planck  =  6.626176e-34
     qproton  =  1.6022e-19
     L0  =  setdiff(who("local"),  L0)
     execstr("["+strcat(L0,",")+"] = resume("+strcat(L0,",")+")")
endfunction
// In your scilab.ini/.scilab :
load(path_to_set_constantes_sci+"/lib")
// Where you need constantes:
set_constantes()
// Then use the constantes defined in set_constantes()
The main advantage with this is that you don't need to remember where 
set_constantes.sci is stored (to exec() it).
But nothing is protected: neither the library, nor set_constantes(), nor 
the constantes it defines.
--> clear avog
--> set_constantes()
--> avog
  avog  =
    6.022D+23
HTH
Samuel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.scilab.org/pipermail/users/attachments/20160304/fa3f6051/attachment.htm>
    
    
More information about the users
mailing list