Re: [Scilab-users] global constant definition for module
Write it to a file?JÅ___ users mailing list users@lists.scilab.org http://lists.scilab.org/mailman/listinfo/users
Re: [Scilab-users] global constant definition for module
Le 04/03/2016 23:33, Samuel Gougeon a écrit : 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. . Actually, there are one or two solutions : 1. Set and store your constants in a TCL session (the main one or a slave), and recall them from it. Data in TCL sessions are not cleared by clear() nor by clearglobal(). This is what i use in drivers published on the fileexchange to set/get "persistent" communication parameters with devices. 2. May be the same could be possible with java objects? I have never tried. 3. Another solution is to use the userdata field of the default figure. The default figure (gdf()) is not clearable. But then all your graphic windows will embed your constants in their .userdata. So it is preferable not to have MBytes of constantes ;) And to set a struct() in userdata. This is a rather bad hacking. May be there are other solutions. Let's free your imagination :) Samuel ___ users mailing list users@lists.scilab.org http://lists.scilab.org/mailman/listinfo/users
Re: [Scilab-users] global constant definition for module
Le 04/03/2016 23:33, Samuel Gougeon a écrit : .../... // 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). The other advantage is that, contrarily to with "global", we don't need to list the names of variables to be set as global. This list is defined inside set_constantes(). It becomes implicit from outside. SG ___ users mailing list users@lists.scilab.org http://lists.scilab.org/mailman/listinfo/users
Re: [Scilab-users] global constant definition for module
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 ___ users mailing list users@lists.scilab.org http://lists.scilab.org/mailman/listinfo/users
Re: [Scilab-users] global constant definition for module
Le 03/03/2016 10:03, David Chèze a écrit : Hi Serge, thanks for this solution. I've just run your example on scilab 6 beta 1 and it fails complaining about undefined variable A. then I ran the example for lib function in scilab help and it fails equally : it looks like it is broken then I will report a bug on this unless already done. The example of the lib() help page is completely outdated. We could update and improve the page whether lib() keeps any interest wrt load(), or not. IMO, it would be preferable to upgrade load() -- mainly to make it able to return the list of names of loaded variables --, and undocument lib(), as written earlier in this thread. Regards Samuel ___ users mailing list users@lists.scilab.org http://lists.scilab.org/mailman/listinfo/users
Re: [Scilab-users] global constant definition for module
>De: Samuel GOUGEON, Jeudi 3 Mars 2016 11:56:15 >However, we could ask to merge lib() in load() and remove it. I should have written: We could ask to merge lib() in load() and UNDOCUMENT lib() in order to make it an internal. (and obviously avoid any back-compatibility issue: lib() is heavily used, like load()) SG ___ users mailing list users@lists.scilab.org http://lists.scilab.org/mailman/listinfo/users
Re: [Scilab-users] global constant definition for module
Hi Serge, thanks for this solution. I've just run your example on scilab 6 beta 1 and it fails complaining about undefined variable A. then I ran the example for lib function in scilab help and it fails equally : it looks like it is broken then I will report a bug on this unless already done. Thank you David -- View this message in context: http://mailinglists.scilab.org/global-constant-definition-for-module-tp4033598p4033606.html Sent from the Scilab users - Mailing Lists Archives mailing list archive at Nabble.com. ___ users mailing list users@lists.scilab.org http://lists.scilab.org/mailman/listinfo/users
[Scilab-users] global constant definition for module
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? David -- View this message in context: http://mailinglists.scilab.org/global-constant-definition-for-module-tp4033598.html Sent from the Scilab users - Mailing Lists Archives mailing list archive at Nabble.com. ___ users mailing list users@lists.scilab.org http://lists.scilab.org/mailman/listinfo/users