2024-01-02 15:45:34 +00:00
|
|
|
defun repeat(n f) {
|
|
|
|
while (> n 0) {
|
|
|
|
f;
|
|
|
|
set n (- n 1);
|
|
|
|
};
|
|
|
|
};
|
2022-03-06 00:39:13 +00:00
|
|
|
|
2024-01-02 15:45:34 +00:00
|
|
|
defun test-non-local-ret-1(k) {
|
|
|
|
repeat 10 (fun() {
|
|
|
|
set k (+ k 2);
|
|
|
|
if (= k 28) { return-from-home k };
|
|
|
|
});
|
2022-03-06 00:39:13 +00:00
|
|
|
|
2024-01-02 15:45:34 +00:00
|
|
|
return k;
|
|
|
|
};
|
2022-03-06 00:39:13 +00:00
|
|
|
|
2024-01-02 15:45:34 +00:00
|
|
|
set a (test-non-local-ret-1 20);
|
|
|
|
if (/= a 28) { printf "ERROR: a must be 28\n" }
|
|
|
|
else { (printf "OK %d\n" a) };
|
2022-03-06 00:39:13 +00:00
|
|
|
|
2024-01-02 15:45:34 +00:00
|
|
|
set a (test-non-local-ret-1 21);
|
|
|
|
if (/= a 41) { printf "ERROR: a must be 41\n" }
|
|
|
|
else { printf "OK %d\n" a };
|
2022-03-06 00:39:13 +00:00
|
|
|
|
2022-02-19 17:26:26 +00:00
|
|
|
|
2024-01-02 15:45:34 +00:00
|
|
|
defun ff() { return 999 };
|
2022-02-19 17:26:26 +00:00
|
|
|
|
2023-11-11 08:57:18 +00:00
|
|
|
## test a normal block return
|
2024-01-02 15:45:34 +00:00
|
|
|
set a (ff);
|
|
|
|
if (/= a 999) { printf "ERROR: a must be 999\n" }
|
|
|
|
else { printf "OK %d\n" a };
|
2022-02-19 17:26:26 +00:00
|
|
|
|
2023-11-11 08:57:18 +00:00
|
|
|
## return from top-level
|
2024-01-02 15:45:34 +00:00
|
|
|
return 10;
|
|
|
|
printf "ERROR: this line must not be printed\n";
|