For example, I would write:
x = 2 y = x + 4 print(y) x = 5 print(y)
And he will output:
6 (=2+4) 9 (=5+4)
In addition, are there cases where this can actually be useful?
Specification: Yes, lambda, etc. solve this problem (they were, as I came to this idea); I was wondering if there are certain languages in which it was by default: no functions or lambda keys are required.
Haskell , , ( , x ).
x
y = x + 4 , y = map (+4) [1..] ( 4 1 ), y? , , ? (: ). , , .
y = x + 4
y = map (+4) [1..]
y
, Haskell y - , x+4, x , , 2.
x+4
, .
Lua:
x = function() return 2 end y = function() return x() + 4 end print(y()) x = function() return 5 end print(y())
$ lua x.lua 6 9
Python ( , x):
x = lambda: 2 y = lambda: x() + 4 print(y()) x = lambda: 5 print(y())
$ python x.py 6 9
func #
Func<int, int> y = (x) => x + 5; Console.WriteLine(y(5)); // 10 Console.WriteLine(y(3)); // 8
... ...
int x = 0; Func<int> y = () => x + 5; x = 5; Console.WriteLine(y()); // 10 x = 3; Console.WriteLine(y()); // 8
... , , , .
, F #, Haskell Scala. Scala , apply(), , . , Scala .
: , , , , Lisps (, Scheme).
.
. 60 , , .
Lucid , x y "", . :
y where y = x + 4 end
:
x(0): 2 y = 6 x(1): 5 y = 7
, Lucid ( ) , , . ( )
F # Wikipedia .
, , , F # .
, !
, , . (Tradestation, metastock ..), (, /), , , , .
My 2c: , , , , . , r. (javascript) , r- (, , ) n-fold:
var x = 2; var y = function() { return x+2; } alert(y()); x= 5; alert(y());
Self , . ( ), .
Scala .
def foo(x : => Int) { println(x) println(x) // x is evaluated again! }
, , Octave, R Maxima. , , , .
Source: https://habr.com/ru/post/1719474/More articles:Json tool for XML? - jsonUsing a previously generated RSA public / private key with .net infrastructure - securityConvert a whole to color, starting with red and cyclic - colorsКак ссылаться на атрибут XML с помощью XPath? - xpathSample code. Why can I access this NSString object after I released it? - objective-cПринуждение PictureBox сохранить изображение, если изображение было нарисовано с использованием кода в vb.net - vb.netC # DataGridView - Transparent Image - c #What is the impact of performance on using jquery functions? - performanceЕсть ли бесплатная библиотека, которая реализует очередь сообщений, похожую на MSMQ (Microsoft Message Queuing)? - c#Programming API VC ++ win32: how can I get an image from the clipboard and display it in windows? - c ++All Articles