The same intention may also get fulfilled with passing a lambdified "callback", potentially with an ALAP-associatively mapped callback-wrapper.
var f = lambda(n:int){ return -2 * n;};
writeln( f( 123 ) ); // lambda --> -246
proc update( x: int(32) ) { // Brian's wish
return 2*x;
}
proc dynamics( x: int(32), f ) { // Vass' solution
return f( x );
}
// ---------------------------------------------------------------------------
writeln( dynamics( 7, f ) ); // proof-of-work [PASS] --> -14
var A = [ lambda( n:int ){ return 10 * n; }, // associatively mapped lambdified-"callbacks"
lambda( n:int ){ return 20 * n; },
lambda( n:int ){ return 30 * n; }
];
// ---------------------------------------------------------------------------
writeln( dynamics( 8, lambda(i:int){ return f(i); } ) ); // proof-of-work [PASS] --> -16
writeln( dynamics( 8, lambda(i:int){ return A[1](i); } ) ); // proof-of-work [PASS] --> 80
// ---------------------------------------------------------------------------
forall funIDX in 1..3 do
writeln( dynamics( 8, A[funIDX] ) ); // proof-of-work [PASS] --> 80 | 160 | 240
The whole TiO.run online-IDE mock-up code is here.
proc this(args)
for it.myRecord(args)
will call that. – Bakeman