Re: [Scilab-users] How to replicate what "load" does (aka creating variable in the current workspace from inside a function)

2016-02-23 Thread amonmayr

Le 02/23/2016 10:25 AM, antoine.el...@scilab-enterprises.com a écrit :

Hi users,

Just to explain, why "who" change.
Previous implementation of "who" was stack dependant, so when you ask 
local variables names,
Scilab 5 reads the stack from bottom to top ( or the opposite ), and 
returns list of variables it found.


Now in Scilab 6, we have remove this stack ( i'm sure you already know 
that ^^ ).

And we use map to store local variables names.
maps are pretty fast but do not ensure order of elements.
"who" returns a list of local variables names, that's all.

The alphabetical order is a side effect of implementation like 
creation order was in Scilab 5.
If we use another system to store local variables names, we can get 
another output.


So please, do not use "alphabetical" order without "sorted" argument. 
It may change in future.


OK, thanks for the in-depth explanations.
Any chance to get some sort of time-stamp or order info with 'who' or 
any other function?
Because that was a neat feature to know right away what were the last 
variables created.





Antoine
ps: I'm pretty sure that "who"'s help page does not say "'who' returns 
variables names in creation order."

Indeed, it does not.
But now we have an option to sort them whereas they are already sorted. 
Kind of weird and confusing.


Le 2016-02-22 12:51, Antoine Monmayrant a écrit :

Not sure if it is related to `who` or to the special use of `resume`.


I can confirm that it comes from the bug in who for scilab 6.0.
See also my solution that uses 'resume' and not 'who' and work in both
5.5 and 6.0

Cheers,

Antoine


___
users mailing list
users@lists.scilab.org
http://lists.scilab.org/mailman/listinfo/users

___
users mailing list
users@lists.scilab.org
http://lists.scilab.org/mailman/listinfo/users




--
+++

 Antoine Monmayrant LAAS - CNRS
 7 avenue du Colonel Roche
 BP 54200
 31031 TOULOUSE Cedex 4
 FRANCE

 Tel:+33 5 61 33 64 59
 
 email : antoine.monmayr...@laas.fr

 permanent email : antoine.monmayr...@polytechnique.org

+++

___
users mailing list
users@lists.scilab.org
http://lists.scilab.org/mailman/listinfo/users


Re: [Scilab-users] How to replicate what "load" does (aka creating variable in the current workspace from inside a function)

2016-02-23 Thread antoine . elias

Hi users,

Just to explain, why "who" change.
Previous implementation of "who" was stack dependant, so when you ask 
local variables names,
Scilab 5 reads the stack from bottom to top ( or the opposite ), and 
returns list of variables it found.


Now in Scilab 6, we have remove this stack ( i'm sure you already know 
that ^^ ).

And we use map to store local variables names.
maps are pretty fast but do not ensure order of elements.
"who" returns a list of local variables names, that's all.

The alphabetical order is a side effect of implementation like creation 
order was in Scilab 5.
If we use another system to store local variables names, we can get 
another output.


So please, do not use "alphabetical" order without "sorted" argument. It 
may change in future.



Antoine
ps: I'm pretty sure that "who"'s help page does not say "'who' returns 
variables names in creation order."


Le 2016-02-22 12:51, Antoine Monmayrant a écrit :

Not sure if it is related to `who` or to the special use of `resume`.


I can confirm that it comes from the bug in who for scilab 6.0.
See also my solution that uses 'resume' and not 'who' and work in both
5.5 and 6.0

Cheers,

Antoine


___
users mailing list
users@lists.scilab.org
http://lists.scilab.org/mailman/listinfo/users

___
users mailing list
users@lists.scilab.org
http://lists.scilab.org/mailman/listinfo/users


Re: [Scilab-users] How to replicate what "load" does (aka creating variable in the current workspace from inside a function)

2016-02-22 Thread Samuel Gougeon
Le 22/02/2016 12:12, Antoine Monmayrant a écrit : Le Lundi 22 Février 
2016 12:04 CET, "Antoine Monmayrant"  a écrit:

  Le Lundi 22 Février 2016 11:51 CET, Serge Steer  a 
écrit:

The following function does the job:

function myload()
txt=["a=1";"b=2"];
ncur= size(who("local"),"*")
execstr(txt);
vars=who("local");
vars=vars(1:size(vars,'*')-ncur-1)
args=strcat(vars,",")
execstr("["+args+"]=resume("+args+")")
endfunction

Thank you Serge!
It does work on 5.5.0, but it does not work on 6.6.0-beta1.
It might be due to the way variables are ordered when calling "who".

OK, it seems that "who" no longer list variables with the most recent at the 
top, but in alphabetical order.

.
You can use setdiff() to get the names of the new variables, knowing the 
former set, whatever is their order.
Then, you will need to the same before and after calling the function, 
to get the unknown names of returned variables.


Samuel

___
users mailing list
users@lists.scilab.org
http://lists.scilab.org/mailman/listinfo/users


Re: [Scilab-users] How to replicate what "load" does (aka creating variable in the current workspace from inside a function)?

2016-02-22 Thread Serge Steer

The following function does the job:

function myload()
  txt=["a=1";"b=2"];
  ncur= size(who("local"),"*")
  execstr(txt);
  vars=who("local");
  vars=vars(1:size(vars,'*')-ncur-1)
  args=strcat(vars,",")
  execstr("["+args+"]=resume("+args+")")
endfunction

Serge
Le 22/02/2016 11:21, Antoine Monmayrant a écrit :

Hi all,

I need to create variables dynamically depending on what I parse from a text 
file.
For testing, I just made a simple script that parses the file and generates a 
string array that defines some variables:
 txt=["a=1";"b=2"];
I then
 execstr(txt);;
to create the variables needed (here "a" and "b").
So far, so good.
Now, I need to refactor my code to turn my messy script into a proper set of 
functions (see example code below).
The issue now is that I can't figure out how to define "a" and "b" from within 
the function.
I tried to declare them as "global" inside the function, but it does not work: 
as I haven't  declared them global at the top level before calling my function, it cannot 
work.
Sadly, as I don't know in advance the variables I'll find when I parse the 
file, I cannot declare the variables global at the top level.

Any solution or workaround?

Cheers,

Antoine

/example code

//script version:

clear a b;
exists("a")// nope
exists("b")// nope
txt=["a=1";"b=2"];//typical result from parsing my txt file
execstr(txt);
exists("a")// yes
exists("b")// yes

//now with a function

//broken & useless
function myload()
 txt=["a=1";"b=2"];
 //string to declare a and b global
 globaltxt="global "+strsubst(txt, '/=.*/', ';','r');
 //does not work
 execstr(globaltxt);
 execstr(txt);
endfunction


//does not work
clear a b;
exists("a")// nope
exists("b")// nope
myload()//
exists("a")// nope
exists("b")// nope


//this will work
clear a b
exists("a")// nope
exists("b")// nope
global a b // well I can't do that in practice, I don't know a and b in advance
myload()//
exists("a")// nope
exists("b")// nope



___
users mailing list
users@lists.scilab.org
http://lists.scilab.org/mailman/listinfo/users



___
users mailing list
users@lists.scilab.org
http://lists.scilab.org/mailman/listinfo/users


[Scilab-users] How to replicate what "load" does (aka creating variable in the current workspace from inside a function)?

2016-02-22 Thread Antoine Monmayrant
Hi all,

I need to create variables dynamically depending on what I parse from a text 
file.
For testing, I just made a simple script that parses the file and generates a 
string array that defines some variables:
txt=["a=1";"b=2"];
I then 
execstr(txt);;
to create the variables needed (here "a" and "b").
So far, so good.
Now, I need to refactor my code to turn my messy script into a proper set of 
functions (see example code below).
The issue now is that I can't figure out how to define "a" and "b" from within 
the function.
I tried to declare them as "global" inside the function, but it does not work: 
as I haven't  declared them global at the top level before calling my function, 
it cannot work.
Sadly, as I don't know in advance the variables I'll find when I parse the 
file, I cannot declare the variables global at the top level.

Any solution or workaround?

Cheers,

Antoine

/example code

//script version:

clear a b;
exists("a")// nope
exists("b")// nope
txt=["a=1";"b=2"];//typical result from parsing my txt file
execstr(txt);
exists("a")// yes
exists("b")// yes

//now with a function

//broken & useless 
function myload()
txt=["a=1";"b=2"];
//string to declare a and b global
globaltxt="global "+strsubst(txt, '/=.*/', ';','r');
//does not work
execstr(globaltxt);
execstr(txt);
endfunction


//does not work
clear a b;
exists("a")// nope
exists("b")// nope
myload()//
exists("a")// nope
exists("b")// nope


//this will work
clear a b
exists("a")// nope
exists("b")// nope
global a b // well I can't do that in practice, I don't know a and b in advance
myload()//
exists("a")// nope
exists("b")// nope



___
users mailing list
users@lists.scilab.org
http://lists.scilab.org/mailman/listinfo/users