[Scilab-users] Anonymous functions

Pierre Vuillemin contact at pierre-vuillemin.fr
Tue Jan 17 08:23:01 CET 2017


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



More information about the users mailing list