2024-09-28 02:57:56 +00:00
|
|
|
fun aaa(a b) {
|
2023-11-12 14:03:39 +00:00
|
|
|
| c |
|
|
|
|
set c (+ a b);
|
|
|
|
return c;
|
|
|
|
};
|
|
|
|
|
|
|
|
set k (aaa 10 20);
|
|
|
|
|
2024-09-03 03:18:08 +00:00
|
|
|
if (== k 30) {
|
2024-01-18 10:16:05 +00:00
|
|
|
printf "OK - %d\n" k;
|
|
|
|
} else {
|
|
|
|
printf "ERROR - %d\n" k;
|
|
|
|
};
|
2023-11-12 14:03:39 +00:00
|
|
|
|
2023-11-14 03:20:47 +00:00
|
|
|
## --------------------------------------
|
2023-11-12 14:03:39 +00:00
|
|
|
|
2024-09-28 02:57:56 +00:00
|
|
|
fun mkfun(t) {
|
2023-11-14 03:20:47 +00:00
|
|
|
return (fun(c) {
|
|
|
|
return (+ t c);
|
|
|
|
});
|
2024-03-09 05:16:51 +00:00
|
|
|
}
|
|
|
|
|
2024-09-28 02:57:56 +00:00
|
|
|
fun mkfun2(t) {
|
2024-03-09 05:16:51 +00:00
|
|
|
return {fun(c) {
|
|
|
|
return (fun(d) {
|
2024-03-09 08:10:51 +00:00
|
|
|
return (+ d c t)
|
2024-03-09 05:16:51 +00:00
|
|
|
})
|
|
|
|
}}
|
|
|
|
}
|
2023-11-12 14:03:39 +00:00
|
|
|
|
2024-03-09 02:57:02 +00:00
|
|
|
f := (mkfun 20);
|
2023-11-14 03:20:47 +00:00
|
|
|
set k (f 50);
|
2024-09-03 03:18:08 +00:00
|
|
|
if (== k 70) {
|
2024-01-18 10:16:05 +00:00
|
|
|
printf "OK - %d\n" k;
|
|
|
|
} else {
|
|
|
|
printf "ERROR - %d\n" k;
|
|
|
|
};
|
2023-11-15 00:58:02 +00:00
|
|
|
|
2024-03-09 02:57:02 +00:00
|
|
|
k := {
|
|
|
|
(mkfun 20) 30
|
|
|
|
}
|
2024-09-03 03:18:08 +00:00
|
|
|
if (== k 50) {
|
2024-03-09 02:57:02 +00:00
|
|
|
printf "OK - %d\n" k
|
|
|
|
} else {
|
|
|
|
printf "ERROR - %d\n" k
|
|
|
|
};
|
|
|
|
|
|
|
|
k := {
|
2024-03-09 08:10:51 +00:00
|
|
|
(mkfun 20) 30 ## the return value of this expression is ignored
|
|
|
|
(mkfun 20) 40 ## the return value of this expression is the return value of the block expression
|
2024-03-09 02:57:02 +00:00
|
|
|
}
|
2024-09-03 03:18:08 +00:00
|
|
|
if (== k 60) {
|
2024-03-09 02:57:02 +00:00
|
|
|
printf "OK - %d\n" k
|
|
|
|
} else {
|
|
|
|
printf "ERROR - %d\n" k
|
|
|
|
};
|
2023-11-15 00:58:02 +00:00
|
|
|
|
2024-03-09 13:48:04 +00:00
|
|
|
k := (((mkfun2 10) 40) 30)
|
2024-09-03 03:18:08 +00:00
|
|
|
if (== k 80) {
|
2024-03-09 05:16:51 +00:00
|
|
|
printf "OK - %d\n" k
|
|
|
|
} else {
|
|
|
|
printf "ERROR - %d\n" k
|
|
|
|
};
|
2023-11-15 00:58:02 +00:00
|
|
|
## --------------------------------------
|
|
|
|
|
2024-03-10 03:09:56 +00:00
|
|
|
## multiple return values
|
2024-09-28 02:57:56 +00:00
|
|
|
fun f(a :: b c) { b := (+ a 10); c := (+ a 20) }
|
2024-03-10 03:09:56 +00:00
|
|
|
[x, y] := (f 9)
|
2024-09-03 03:18:08 +00:00
|
|
|
if (== x 19) {
|
2024-03-10 03:09:56 +00:00
|
|
|
printf "OK - %d\n" x
|
|
|
|
} else {
|
|
|
|
printf "ERROR - %d\n" x
|
|
|
|
}
|
2024-09-03 03:18:08 +00:00
|
|
|
if (== y 29) {
|
2024-03-10 03:09:56 +00:00
|
|
|
printf "OK - %d\n" y
|
|
|
|
} else {
|
|
|
|
printf "ERROR - %d\n" y
|
|
|
|
}
|
|
|
|
|
2024-03-10 13:38:01 +00:00
|
|
|
## --------------------------------------
|
2024-09-28 02:57:56 +00:00
|
|
|
k := (fun qq(t) (+ t 20))
|
2024-03-10 13:38:01 +00:00
|
|
|
x := (k 8)
|
|
|
|
y := (qq 9)
|
|
|
|
|
2024-09-03 03:18:08 +00:00
|
|
|
if (== x 28) {
|
2024-03-10 13:38:01 +00:00
|
|
|
printf "OK - %d\n" x
|
|
|
|
} else {
|
|
|
|
printf "ERROR - %d\n" x
|
|
|
|
}
|
|
|
|
|
2024-09-03 03:18:08 +00:00
|
|
|
if (== y 29) {
|
2024-03-10 13:38:01 +00:00
|
|
|
printf "OK - %d\n" x
|
|
|
|
} else {
|
|
|
|
printf "ERROR - %d\n" x
|
|
|
|
}
|
|
|
|
|
2024-03-10 03:09:56 +00:00
|
|
|
## --------------------------------------
|
|
|
|
|
2024-07-09 14:44:24 +00:00
|
|
|
defclass A [ a b c ] {
|
2024-09-28 02:57:56 +00:00
|
|
|
fun :* newInstance(x y z) {
|
2024-03-09 02:57:02 +00:00
|
|
|
set a x
|
|
|
|
set b y
|
|
|
|
set c z
|
|
|
|
return self
|
2023-11-15 00:58:02 +00:00
|
|
|
};
|
|
|
|
|
2024-09-28 02:57:56 +00:00
|
|
|
fun get-a() { return a; };
|
|
|
|
##fun get-b() b;
|
|
|
|
##fun get-c() c;
|
2023-11-15 00:58:02 +00:00
|
|
|
};
|
|
|
|
|
2024-03-07 15:23:52 +00:00
|
|
|
k := (A:newInstance 11 22 33);
|
|
|
|
##set k (A:newInstance 11 22 33);
|
|
|
|
|
2024-01-01 16:41:41 +00:00
|
|
|
set v (k:get-a);
|
2024-09-03 03:18:08 +00:00
|
|
|
if (== v 11) {
|
2024-01-18 10:16:05 +00:00
|
|
|
printf "OK - %d\n" v;
|
|
|
|
} else {
|
|
|
|
printf "ERROR - %d\n" v;
|
|
|
|
};
|