Code: Select all
Procedure SomeFunction()
Protected a.l=1
Protected b.l=2
;/ Lambda as a function with capture group
Lambda.l [a, b]SomeLambda(c.l)
LambdaReturn a+b+c
EndLambda
;/ Lambda as a c-function with capture group
LambdaC.l [a, b]SomeLambdaC(c.l)
LambdaReturn a+b+c
EndLambda
;/ Lambda as a thread function with capture group
Lambda [a, b]SomeLambdaThread(*Tuple.TUPLE_INT_2)
PokeI(*Tuple\i[1],a+b+*Tuple\i[0])
EndLambda
;/ 1 + 2 + 3 = 6
Debug SomeLambda(3)
Debug CallFunctionFast(SomeLambda(3))
Debug CallCFunctionFast(SomeLambdaC(3))
Protected Result.Long
ThreadId=CreateThread(SomeLambdaThread,TupleI2(3, @Result))
WaitThread(ThreadId)
;/ 6
Debug Result\l
EndProcedure
See here for some examples of my frustrations with whitespace:
http://www.purebasic.fr/english/viewtop ... =3&t=66631
Can anyone propose a format for anonymous lambda functions that would look reasonable with PureBasic syntax rules?