[Scilab-users] Passing function argument by reference

classic Classic list List threaded Threaded
9 messages Options
Grzegorz Grzegorz
Reply | Threaded
Open this post in threaded view
|

[Scilab-users] Passing function argument by reference

Dear Scilabers,

Is it possible to pass object (tlist) to a function by a reference ?

Example code :

function ref_test(obj)
    obj.a = 10; 
endfunction

o = tlist(["tlisttype", "a", "b"], 0, 0);

ref_test(o)

if o.a == 10 then
    disp("works");
else
    disp("do not works");
end

Regards Grzegorz

_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
Rafael Guerra Rafael Guerra
Reply | Threaded
Open this post in threaded view
|

Re: Passing function argument by reference

Hi,

 

This seems to be a question of global and local scope of variables.

You can try:

 

function o2=ref_test(obj)

    o2 = obj;

    o2.a = 10;

endfunction

 

o = tlist(["tlisttype", "a", "b"], 0, 0);

 

o2 = ref_test(o);

 

if o2.a == 10 then

    disp("It works");

else

    disp("It does not work");

end

 

Regards,

Rafael


_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
Rafael Guerra Rafael Guerra
Reply | Threaded
Open this post in threaded view
|

Re: Passing function argument by reference

In reply to this post by Grzegorz

Using global variables instead:

 

global obj;

obj = tlist(["tlisttype", "a", "b"], 0, 0);

 

function ref_test(obj)

    global obj;

    obj.a = 10;

endfunction

 

ref_test(obj);

 

if obj.a == 10 then

    disp("It works");

else

    disp("It does not work");

end


_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
Rafael Guerra Rafael Guerra
Reply | Threaded
Open this post in threaded view
|

Re: Passing function argument by reference

In reply to this post by Grzegorz

Proszę


_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
Grzegorz Grzegorz
Reply | Threaded
Open this post in threaded view
|

Re: Passing function argument by reference

Thank you Rafael,

I was looking for solution which allow object (tlist) modification by function call but it seems that it is not possible to implement the following without globals or using function return argument.

function addChannelToSession(obj, arg)
    obj.channel = arg;
endfunction

function obj=createSession()
    obj = tlist(["tlisttype", "channel"], []);
endfunction

s = createSession(); 
// s.channel is []
addChannelToSession(s, 1); 
// s.channel is 1
Regards Grzegorz

2018-07-03 11:19 GMT+02:00 Rafael Guerra <[hidden email]>:

Proszę


_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users



_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
Rafael Guerra Rafael Guerra
Reply | Threaded
Open this post in threaded view
|

Re: Passing function argument by reference

Hi Grzegorz,

 

You could also use same input object as output:

 

function obj=ref_test(obj)

    obj.a = 10;

endfunction

 

o = tlist(["tlisttype", "a", "b"], 0, 0);

 

o = ref_test(o);

 

if o.a == 10 then

    disp("It works");

else

    disp("It does not work");

end

 

Not much difference in this simple example between: “o = ref_test(o)”  and  ref_test(o)” …

 

Regards,

Rafael


_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
Heinz Nabielek Heinz Nabielek
Reply | Threaded
Open this post in threaded view
|

[Scilab-users] 3d pair correlation function PCF

Colleagues:

is there Scilab [or other] code for the computation of the 3d pair correlation function PCF of particles in a spherical volume?
Heinz
_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
Rafael Guerra Rafael Guerra
Reply | Threaded
Open this post in threaded view
|

Re: 3d pair correlation function PCF

Hi Heinz,

Have you checked following codes (both 2D and 3D cases provided) for particles inside a cubic volume:
https://github.com/cfinch/Shocksolution_Examples/blob/master/PairCorrelation/paircorrelation.py

It might be possible to adapt that code from a cubic volume to a spherical one.
For instance, it comes to mind evaluating if:    rMax + d < R,
where 'rMax' is as per code definition and 'd' is the distance of the particles from the center of the sphere with radius R

Regards,
Rafael

_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
Heinz Nabielek-3 Heinz Nabielek-3
Reply | Threaded
Open this post in threaded view
|

Re: 3d pair correlation function PCF

On 07.07.2018, at 13:25, Rafael Guerra <[hidden email]> wrote:

Hi Heinz,

Have you checked following codes (both 2D and 3D cases provided) for particles inside a cubic volume:
https://github.com/cfinch/Shocksolution_Examples/blob/master/PairCorrelation/paircorrelation.py

It might be possible to adapt that code from a cubic volume to a spherical one.
For instance, it comes to mind evaluating if:    rMax + d < R,
where 'rMax' is as per code definition and 'd' is the distance of the particles from the center of the sphere with radius R

Great many thanks. As a complete python novice, I just got it running as is (with difficulties). I keep working on it.
Heinz



_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users