RosettaCodeData/Task/Anonymous-recursion/M2000-Interpreter/anonymous-recursion.m2000

31 lines
987 B
Plaintext

Module Anonymus_lambda (x, result){
global Err = lambda (x) ->{
if x=1 then Error "Negative input"
}
' in one line - so Error have to call it through a global function
Print lambda (x as long long)->{=if(x<0->Err(1), lambda (x)->{=If(x>1->lambda(x-1)+lambda(x-2), x)}(x))}(x)=result
}
Anonymus_Lambda 10, 55
Anonymus_Lambda 7, 13
Try Ok {
Anonymus_Lambda -7, 13 ' return false, and also we have error
' so here we exit from block - no printing "nothing"
Print "nothing"
}
If error or not ok then Report Error$
Module Anonymus_lambda (x, result){
' Using multiple lines for the Lambda - so Error can be used here
Print lambda (x as long long)->{
if x<0 then Error "Negative input"
=lambda (x)->{=If(x>1->lambda(x-1)+lambda(x-2), x)}(x)
}(x)=result
}
Anonymus_Lambda 10, 55
Anonymus_Lambda 7, 13
Try Ok {
Anonymus_Lambda -7, 13 ' nothing return we have error
' so here we exit from block - no printing "nothing"
Print "nothing"
}
If error or not ok then Report Error$