[Scilab-users] Anonymous functions
Serge Steer
Serge.Steer at inria.fr
Tue Jan 17 10:38:15 CET 2017
A partial solution should be
deff("y=f(x)","a="+sci2exp(a,0)+";y=a*x")
but it may cause numerical problem as a is formatted
Regards
Serge Steer
On 17/01/2017 08:23, Pierre Vuillemin wrote:
> Hi all,
>
> I am trying to reproduce the behaviour of anonymous function in Scilab
> (see the code in lambdaFun here: https://github.com/pivui/scilabTools).
>
> At the moment, it works like in Matlab, for instance:
>
> a = eye(3,3);
> lambda 'f(x) = a*x' // the name of the lambda function will be f
> a = rand(3,3) // the value of 'a' is saved in the lambda
> function when it is created
> f(ones(3,1)) // gives [1,1,1]'
>
> I would like to emulate the behaviour of lambda function of python as
> well. In that case, 'a' should change when the initial variable
> changes, for instance
>
> a = 2
> f = lambda : a
> def fun():
> a = 4
> return f
> a = 3
> f() // should return 3
> fun() // should return 3 -> it does not take the variable 'a' in the
> function namespace
>
> I need to remember where the value or a is stored, I don't know if it
> is possible?
>
> Regards,
>
> Pierre
> _______________________________________________
> users mailing list
> users at lists.scilab.org
> http://lists.scilab.org/mailman/listinfo/users
>
More information about the users
mailing list