Talk:Functional()
Jump to navigation
Jump to search
Is my example correct?
I have an idea for an example. Does it do what I think it must do i. e. does it input character and print '!' if it is odd before inputting?
0, 1, ==, =, var, [], read, write, eof, read()([](), 1)([]()(write(1), write(0), write(0), write(0), write(0), write(1))())
If it doesn't do that, what does it do? Orisphera (talk) 15:05, 19 September 2018 (UTC)
- Nice example! You are very close, it prints "!" if the first input character is even (the least significant bit is 0). The
[]()
is an instance of FunctionTemplate, which is the only function that interprets its arguments as a function body and doesn't evaluate them immediately. That's basically what you have in your example: if the first bit is 1 (odd) then construct a new function (which never gets called, and thus doesn't print anything). If the bit is 0 (even) then evaluate the argument (which is an immediately-invoked function expression that prints "!"). Feel free to edit the main page and add this example if you want. --Hakerh400 (talk) 16:50, 28 September 2018 (UTC)