Can Matlab do lazy evaluations?

I think you can achieve a lazy score in Matlab this way:

foo = @() 1+1
% do some other things
bar = foo()

As I understand it, a function is not actually evaluated until it is called foo(). Can this be confirmed if this is considered a lazy assessment or not?

+4
source share
1 answer

As far as I know, there is no better way to achieve this in Matlab, here it is also offered here . Just keep in mind that Matlab will not detect multiple ratings of the same term. If you do things like:

foo = @() 1+1
bar=@()foo()*foo()

He will evaluate foo twice. Instead, the "traditional" way will evaluate it once:

foo=1+1
bar=foo+foo
+3
source

Source: https://habr.com/ru/post/1628619/


All Articles