Inverted syntax: Difference between revisions

Content added Content deleted
Line 456: Line 456:


=={{header|M2000 Interpreter}}==
=={{header|M2000 Interpreter}}==
There is no way to have inverted syntax for conditionals, except for using lambda functions. Two more things we can do. One to invert the way we call a module, passing statements before calling the module. The Second by using Let we make a Push and then a Read, so first evaluated the right expression and then the left. Here we change a global variable in the right expression and we change the index of array where we set the returned value from function.
There is no way to have inverted syntax for conditionals, except for using lambda functions. Three more things we can do. One to invert the way we call a module, passing statements before calling the module. The Second by using Let we make a Push and then a Read, so first evaluated the right expression and then the left. Here we change a global variable in the right expression and we change the index of array where we set the returned value from function.
The third one is more complicated. We make a callback function which act as code of a module, with same scope, and use a module to check condition before we call the callback function


<lang M2000 Interpreter>
<lang M2000 Interpreter>
Line 498: Line 499:
\\ executed like these
\\ executed like these
Push 2, 1 : Read X, Y
Push 2, 1 : Read X, Y

\\ This is the CallBack way
Module ExecCond {
Read &callback(), cond
if cond then call callback()
}
x=1
\\ this aa() is a function but when we call it after transforming from Lazy$()
\\ act as part of module so we see x, and alter it
Function aa {
x++
}
a=1
ExecCond Lazy$(&aa()), A=1
Print x=2
</lang>
</lang>