Re: [Scilab-users] Getting the variable name used for a function input argument

2021-12-06 Thread Samuel Gougeon

Hello Jens,

Le 06/12/2021 à 10:40, Jens Simon Strom a écrit :

Hi Samuel,
Your solution is quite sophisticated. 



On the opposite, it aims to be simpler.


To me it was confusing to call a function without the input being 
bracketed. And on top of this, that a variable of type /constant/ is 
accepted as a /string/ within the function.


As a cherry on the cake, the syntax will work as well for literal values:

function  printc(name)
execstr("c = "+name)
//Drucken einer komplexen Zahl mit Betrag und Winkel/°
  Format  =  strsubst(name,"%","%%")+': %f /_%7.2f°\n'
mprintf(Format,  abs(c),  180/%pi*atan(imag(c),  real(c)))
endfunction

--> printc 3-4*%i
3-4*%i: 5.00    /_ -53.13°


Scilab seems to be more flexible than I would dare to imagine before now. 



Handiness is one of the signatures of high level languages.

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


Re: [Scilab-users] Getting the variable name used for a function input argument

2021-12-06 Thread Stéphane Mottelet

Hello Jens.

Nothing sophisticated here.

print myVar

is considered by the parser as

print("myVar")

See "Calling function"/item 4.

https://help.scilab.org/docs/6.1.1/en_US/functions.html

S.

Le 06/12/2021 à 10:40, Jens Simon Strom a écrit :

Hi Samuel,
Your solution is quite sophisticated. To me it was confusing to call a 
function without the input being bracketed. And on top of this, that a 
variable of type /constant/ is accepted as a /string/ within the 
function. Scilab seems to be more flexible than I would dare to 
imagine before now. However it works fine. Thanks again.


Regards
Jens
- 



Am 05.12.2021 um 20:02 schrieb Samuel Gougeon:

Le 04/12/2021 à 20:59, Samuel Gougeon a écrit :


So, /unless you need to know the name *inside* printc() for some 
unsaid purpose/, what would be the difference between in one hand


[name, mag, arg] = printc(myvar, "myvar")

and on the other hand

name = "myvar";
[mag, arg] = printc(myvar)

?



So, after your mail in private, you actually needs the variable's 
name inside the function.
Then, the easiest way to do what you expect could be to pass only the 
name:


function  printc(name)
   execstr("c = "+name)
   //Drucken einer komplexen Zahl mit Betrag und Winkel/°
   mprintf([name+': %f /_%7.2f°\n'],abs(c),  180/%pi*atan(imag(c),real(c)))
endfunction
--> myVar = 3 - 2*%i
myVar =
3. - 2.i

--> printc myVar
myVar: 3.605551 /_ -33.69°

Regards
Samuel


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



___
users mailing list
users@lists.scilab.org
https://antispam.utc.fr/proxy/v3?i=SHV0Y1JZQjNyckJFa3dUQiblhF5YcUqtiWCaK_ri0kk&r=T0hnMlUyVEgwNmlmdHc1NTiGTQVgIg9a1MYkHb_GeosOO-jCQ_NnAucfYCLceioT&f=V3p0eFlQOUZ4czh2enpJS67gBdM2WVME2HqVPefA4FpGU6HeKhrEzrhzAHs-d_Wu&u=http%3A//lists.scilab.org/mailman/listinfo/users&k=ZVd0


--
Stéphane Mottelet
Ingénieur de recherche
EA 4297 Transformations Intégrées de la Matière Renouvelable
Département Génie des Procédés Industriels
Sorbonne Universités - Université de Technologie de Compiègne
CS 60319, 60203 Compiègne cedex
Tel : +33(0)344234688
http://www.utc.fr/~mottelet
___
users mailing list
users@lists.scilab.org
http://lists.scilab.org/mailman/listinfo/users


Re: [Scilab-users] Getting the variable name used for a function input argument

2021-12-06 Thread Jens Simon Strom

Hi Samuel,
Your solution is quite sophisticated. To me it was confusing to call a 
function without the input being bracketed. And on top of this, that a 
variable of type /constant/ is accepted as a /string/ within the 
function. Scilab seems to be more flexible than I would dare to imagine 
before now. However it works fine. Thanks again.


Regards
Jens
- 



Am 05.12.2021 um 20:02 schrieb Samuel Gougeon:

Le 04/12/2021 à 20:59, Samuel Gougeon a écrit :


So, /unless you need to know the name *inside* printc() for some 
unsaid purpose/, what would be the difference between in one hand


[name, mag, arg] = printc(myvar, "myvar")

and on the other hand

name = "myvar";
[mag, arg] = printc(myvar)

?



So, after your mail in private, you actually needs the variable's name 
inside the function.
Then, the easiest way to do what you expect could be to pass only the 
name:


function  printc(name)
   execstr("c = "+name)
   //Drucken einer komplexen Zahl mit Betrag und Winkel/°
   mprintf([name+': %f /_%7.2f°\n'],abs(c),  180/%pi*atan(imag(c),real(c)))
endfunction
--> myVar = 3 - 2*%i
myVar =
3. - 2.i

--> printc myVar
myVar: 3.605551 /_ -33.69°

Regards
Samuel


___
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] Getting the variable name used for a function input argument

2021-12-05 Thread Samuel Gougeon

Le 04/12/2021 à 20:59, Samuel Gougeon a écrit :


So, /unless you need to know the name *inside* printc() for some 
unsaid purpose/, what would be the difference between in one hand


[name, mag, arg] = printc(myvar, "myvar")

and on the other hand

name = "myvar";
[mag, arg] = printc(myvar)

?



So, after your mail in private, you actually needs the variable's name 
inside the function.

Then, the easiest way to do what you expect could be to pass only the name:

function  printc(name)
  execstr("c = "+name)
  //Drucken einer komplexen Zahl mit Betrag und Winkel/°
  mprintf([name+': %f /_%7.2f°\n'],abs(c),  180/%pi*atan(imag(c),real(c)))
endfunction

--> myVar = 3 - 2*%i
myVar =
3. - 2.i

--> printc myVar
myVar: 3.605551 /_ -33.69°

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


Re: [Scilab-users] Getting the variable name used for a function input argument

2021-12-04 Thread Samuel Gougeon

Hello Jens,

Le 04/12/2021 à 20:39, Jens Simon Strom a écrit :

Hi,
Thanks for all the responses and sorry for not beeing able to answer 
before now.


The background of my question was to write a function for formatted 
output of complex variables in polar form with

mprintf like
function printc(c)

which returns the name of c on calling level, |c|, and the angle.

I understand now that I have to write e. g.

function printc(c,cname)

where cname is the wanted string. This can even give some additional 
freedeom in modifying the output name.



So, /unless you need to know the name *inside* printc() for some unsaid 
purpose/, what would be the difference between in one hand


[name, mag, arg] = printc(myvar, "myvar")

and on the other hand

name = "myvar";
[mag, arg] = printc(myvar)

?
BR
Samuel


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


Re: [Scilab-users] Getting the variable name used for a function input argument

2021-12-04 Thread Jens Simon Strom

Hi,
Thanks for all the responses and sorry for not beeing able to answer 
before now.


The background of my question was to write a function for formatted 
output of complex variables in polar form with


mprintf like

function printc(c)

which returns the name of c on calling level, |c|, and the angle.

I understand now that I have to write e. g.

function printc(c,cname)

where cname is the wanted string. This can even give some additional 
freedeom in modifying the output name.


Regards
Jens


Am 24.11.2021 um 09:51 schrieb Stéphane Mottelet:


Hi,

Le 24/11/2021 à 01:42, Federico Miyara a écrit :


I'm not completely sure, but I think this is not possible since what 
is passed to the function isn't a variable but the value contained in 
the variable.
No. Internally, input arguments are passed as references to the true 
object. There is no copy unless an input argument is modified in the 
function (in that case a copy with local scope only).

The name is lost in the process.
Yes, before the first line of the function body the original object 
has the name of the argument, although both names refer to the same 
object.


An alternative way (but I don't know if this would be acceptable for 
you) is that the function had as its argument a variable name (hence, 
a string), so your x would be "xNum", instead of 123. Then you could 
use evstr() to get the value of the variable to proceed with the 
processing.


I think that we are in the presence of an XY problem 
(https://xyproblem.info/) and that Jens should explain the whole story.


S.



Regards,

Federico Miyara


On 23/11/2021 17:18, Jens Simon Strom wrote:


Hi Scilab friends,
Given a numeric variable like xNum as an input argument of a 
function call, how can I produce the variable name string "xNum" 
within the function?


Example:

function [name,y]=foo(x)
   name=???
   y=x^2
endfunction

xNum=123.
[name,y]=foo(xNum)
The result for name should be the string "xNum"

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





 
	Libre de virus. www.avast.com 
 



<#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>

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

--
Stéphane Mottelet
Ingénieur de recherche
EA 4297 Transformations Intégrées de la Matière Renouvelable
Département Génie des Procédés Industriels
Sorbonne Universités - Université de Technologie de Compiègne
CS 60319, 60203 Compiègne cedex
Tel : +33(0)344234688
http://www.utc.fr/~mottelet

___
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] Getting the variable name used for a function input argument

2021-11-27 Thread Samuel Gougeon

Le 23/11/2021 à 21:18, Jens Simon Strom a écrit :


Hi Scilab friends,
Given a numeric variable like xNum as an input argument of a function 
call, how can I produce the variable name string "xNum" within the 
function?



That is requested and commented as the still open report #5840 
 , since 2004.


Samuel

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


Re: [Scilab-users] Getting the variable name used for a function input argument

2021-11-27 Thread Samuel Gougeon

Le 24/11/2021 à 19:34, Stéphane Mottelet a écrit :


Hi,

Le 24/11/2021 à 18:07, Samuel Gougeon a écrit :

Le 24/11/2021 à 09:51, Stéphane Mottelet a écrit :


Hi,

Le 24/11/2021 à 01:42, Federico Miyara a écrit :


I'm not completely sure, but I think this is not possible since 
what is passed to the function isn't a variable but the value 
contained in the variable.
No. Internally, input arguments are passed as references to the true 
object. There is no copy /unless an input argument *is modified*/ in 
the function (in that case a copy with local scope only).



Are you sure about that? Not when they are only reached in read mode?

I might have misunderstood, but i remember a discussion with Clément 
during the last ScilabTech. Clément was categorically stating that 
all input arguments are copied, only and always copied.


It depends on the type of Callable. If you are talking about Scilab 
macros, inputs are (hopefully) never copied. However, if you are 
talking about old-style Scilab 5 C-gateways, yes, there is a wrapper 
that triggers a copy :


https://github.com/opencollab/scilab/blob/master/scilab/modules/ast/src/cpp/types/function.cpp#L333



3 years ago, we were talking about macros in Scilab 6.0.(1)
This huge improvement of Scilab 6 with respect to Scilab 5 can be 
actually tested (below).
As far as i remember,  it was never advertized when Scilab 6.0.0 alpha 
or final version were released. Has it?
Yet, it drastically improves performances, as in many situations huge 
arrays are passed while only a tiny part is extracted and used in the 
function.


So, yes, "hopefully", passed inputs are*/no longer/* copied when only 
addressed, since Scilab 6.

Thanks for having clarified it.


*With Scilab 5.5.2:*

-->a = rand(1000, 1000, 5);

-->function test(aa),b = 1, endfunction
-->tic(); for i = 1:100, test(a); end; toc()
 ans  =
    0.002

-->function test(aa),aa, endfunction   // aa just addressed, without change
-->tic(); for i = 1:100, test(a); end; toc()
 ans  =
3.211

*With Scilab 6.0.0:*

--> a = rand(1000, 1000, 5);

--> function test(aa),b = 1;, endfunction
--> tic(); for i = 1:100, test(a); end; toc()
 ans  =
   0.0003982

--> function test(aa), aa, endfunction
--> tic(); for i = 1:100, test(a); end; toc()
 ans  =
   0.0003522   

--> function test(aa),b = aa(2,2,2), endfunction
--> tic(); for i = 1:100, test(a); end; toc()
 ans  =
   0.0006584

--> function test(aa), aa = 3, endfunction
--> tic(); for i = 1:100, test(a); end; toc()
 ans  =
   0.0003663

--> function test(aa),aa(2,2,2) = 1, endfunction
--> tic(); for i = 1:100, test(a); end; toc()
 ans  =
   1.7976679 as expected


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


Re: [Scilab-users] Getting the variable name used for a function input argument

2021-11-24 Thread Stéphane Mottelet

Hi,

Le 24/11/2021 à 18:07, Samuel Gougeon a écrit :

Le 24/11/2021 à 09:51, Stéphane Mottelet a écrit :


Hi,

Le 24/11/2021 à 01:42, Federico Miyara a écrit :


I'm not completely sure, but I think this is not possible since what 
is passed to the function isn't a variable but the value contained 
in the variable.
No. Internally, input arguments are passed as references to the true 
object. There is no copy /unless an input argument *is modified*/ in 
the function (in that case a copy with local scope only).



Are you sure about that? Not when they are only reached in read mode?

I might have misunderstood, but i remember a discussion with Clément 
during the last ScilabTech. Clément was categorically stating that all 
input arguments are copied, only and always copied.


It depends on the type of Callable. If you are talking about Scilab 
macros, inputs are (hopefully) never copied. However, if you are talking 
about old-style Scilab 5 C-gateways, yes, there is a wrapper that 
triggers a copy :


https://github.com/opencollab/scilab/blob/master/scilab/modules/ast/src/cpp/types/function.cpp#L333

New cppsci gateways always pass arguments by reference, which allows to 
modify arguments. This is a feature which is used (at least) in Julia, 
and the convention they use adds a exclamation mark at the end of the 
name.  This feature is not used in Scilab, this is a pity...


S.



Samuel

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


--
Stéphane Mottelet
Ingénieur de recherche
EA 4297 Transformations Intégrées de la Matière Renouvelable
Département Génie des Procédés Industriels
Sorbonne Universités - Université de Technologie de Compiègne
CS 60319, 60203 Compiègne cedex
Tel : +33(0)344234688
http://www.utc.fr/~mottelet
___
users mailing list
users@lists.scilab.org
http://lists.scilab.org/mailman/listinfo/users


Re: [Scilab-users] Getting the variable name used for a function input argument

2021-11-24 Thread Samuel Gougeon

Le 24/11/2021 à 09:51, Stéphane Mottelet a écrit :


Hi,

Le 24/11/2021 à 01:42, Federico Miyara a écrit :


I'm not completely sure, but I think this is not possible since what 
is passed to the function isn't a variable but the value contained in 
the variable.
No. Internally, input arguments are passed as references to the true 
object. There is no copy /unless an input argument *is modified*/ in 
the function (in that case a copy with local scope only).



Are you sure about that? Not when they are only reached in read mode?

I might have misunderstood, but i remember a discussion with Clément 
during the last ScilabTech. Clément was categorically stating that all 
input arguments are copied, only and always copied.


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


Re: [Scilab-users] Getting the variable name used for a function input argument

2021-11-24 Thread Stéphane Mottelet
Jens, please do not use "Reply to:" on an old thread when this is 
irrelevant.


You can create a new thread by directly mailing users@lists.scilab.org

S.

Le 23/11/2021 à 21:18, Jens Simon Strom a écrit :


Hi Scilab friends,
Given a numeric variable like xNum as an input argument of a function 
call, how can I produce the variable name string "xNum" within the 
function?


Example:

function [name,y]=foo(x)
   name=???
   y=x^2
endfunction

xNum=123.
[name,y]=foo(xNum)
The result for name should be the string "xNum"

Regards
Jens
___
users mailing list
users@lists.scilab.org
https://antispam.utc.fr/proxy/v3?i=Z09lbVhROVBaOHd3NjZZMVfTogSUUCLtvQYv_TI7-Qg&r=eVVJWkdic3NtZTdZV2pycc8oEJBVcQfwoAgOILbixruFQP-mXZOvGI-Awo-iPm4W&f=UU9IMnpkdmJmSk9YOHVtc4JNomkUGubf8DA_bzrUn-Hiq5VuGo_VlJP1TQC7yyVL&u=http%3A//lists.scilab.org/mailman/listinfo/users&k=eFRI 



--
Stéphane Mottelet
Ingénieur de recherche
EA 4297 Transformations Intégrées de la Matière Renouvelable
Département Génie des Procédés Industriels
Sorbonne Universités - Université de Technologie de Compiègne
CS 60319, 60203 Compiègne cedex
Tel : +33(0)344234688
http://www.utc.fr/~mottelet

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


Re: [Scilab-users] Getting the variable name used for a function input argument

2021-11-24 Thread Stéphane Mottelet

Hi,

Le 24/11/2021 à 01:42, Federico Miyara a écrit :


I'm not completely sure, but I think this is not possible since what 
is passed to the function isn't a variable but the value contained in 
the variable.
No. Internally, input arguments are passed as references to the true 
object. There is no copy unless an input argument is modified in the 
function (in that case a copy with local scope only).

The name is lost in the process.
Yes, before the first line of the function body the original object has 
the name of the argument, although both names refer to the same object.


An alternative way (but I don't know if this would be acceptable for 
you) is that the function had as its argument a variable name (hence, 
a string), so your x would be "xNum", instead of 123. Then you could 
use evstr() to get the value of the variable to proceed with the 
processing.


I think that we are in the presence of an XY problem 
(https://xyproblem.info/) and that Jens should explain the whole story.


S.



Regards,

Federico Miyara


On 23/11/2021 17:18, Jens Simon Strom wrote:


Hi Scilab friends,
Given a numeric variable like xNum as an input argument of a function 
call, how can I produce the variable name string "xNum" within the 
function?


Example:

function [name,y]=foo(x)
   name=???
   y=x^2
endfunction

xNum=123.
[name,y]=foo(xNum)
The result for name should be the string "xNum"

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





 
	Libre de virus. www.avast.com 
 



<#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>

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


--
Stéphane Mottelet
Ingénieur de recherche
EA 4297 Transformations Intégrées de la Matière Renouvelable
Département Génie des Procédés Industriels
Sorbonne Universités - Université de Technologie de Compiègne
CS 60319, 60203 Compiègne cedex
Tel : +33(0)344234688
http://www.utc.fr/~mottelet
___
users mailing list
users@lists.scilab.org
http://lists.scilab.org/mailman/listinfo/users


Re: [Scilab-users] Getting the variable name used for a function input argument

2021-11-23 Thread Federico Miyara


I'm not completely sure, but I think this is not possible since what is 
passed to the function isn't a variable but the value contained in the 
variable. The name is lost in the process.


An alternative way (but I don't know if this would be acceptable for 
you) is that the function had as its argument a variable name (hence, a 
string), so your x would be "xNum", instead of 123. Then you could use 
evstr() to get the value of the variable to proceed with the processing.


Regards,

Federico Miyara


On 23/11/2021 17:18, Jens Simon Strom wrote:


Hi Scilab friends,
Given a numeric variable like xNum as an input argument of a function 
call, how can I produce the variable name string "xNum" within the 
function?


Example:

function [name,y]=foo(x)
   name=???
   y=x^2
endfunction

xNum=123.
[name,y]=foo(xNum)
The result for name should be the string "xNum"

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






--
El software de antivirus Avast ha analizado este correo electrónico en busca de 
virus.
https://www.avast.com/antivirus
___
users mailing list
users@lists.scilab.org
http://lists.scilab.org/mailman/listinfo/users


[Scilab-users] Getting the variable name used for a function input argument

2021-11-23 Thread Jens Simon Strom


Hi Scilab friends,
Given a numeric variable like xNum as an input argument of a function 
call, how can I produce the variable name string "xNum" within the function?


Example:

function [name,y]=foo(x)
   name=???
   y=x^2
endfunction

xNum=123.
[name,y]=foo(xNum)
The result for name should be the string "xNum"

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