2024-01-02 04:59:03 +00:00
|
|
|
set t (
|
|
|
|
class | x | {
|
2024-02-04 17:43:50 +00:00
|
|
|
defun :* make() { x := 1234; return self; };
|
2024-01-02 04:59:03 +00:00
|
|
|
defun get-x() { return x };
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
set X t;
|
|
|
|
|
2024-01-18 14:55:50 +00:00
|
|
|
if (nqv? t X) { printf "ERROR: t must point to X\n" } \
|
2024-01-02 04:59:03 +00:00
|
|
|
else { printf "OK: t points to X\n" };
|
|
|
|
|
|
|
|
set t ((t:make):get-x);
|
|
|
|
|
2024-01-18 14:55:50 +00:00
|
|
|
if (nqv? t 1234) { printf "ERROR: t must be 1234\n" } \
|
2024-01-02 04:59:03 +00:00
|
|
|
else { printf "OK: t is %d\n" t };
|
|
|
|
|
|
|
|
|
2024-02-04 17:43:50 +00:00
|
|
|
j := #{ ((X:make):get-x): 9999, 4512: ((X: make): get-x) };
|
|
|
|
v := (dic.get j 1234);
|
2024-01-18 14:55:50 +00:00
|
|
|
if (nqv? v 9999) { printf "ERROR: v is not 9999\n" } \
|
2024-01-02 04:59:03 +00:00
|
|
|
else { printf "OK: value is %d\n" v };
|
|
|
|
|
2024-02-04 17:43:50 +00:00
|
|
|
v := (dic.get j 4512);
|
2024-01-18 14:55:50 +00:00
|
|
|
if (nqv? v 1234) { printf "ERROR: v is not 1234\n" } \
|
2024-01-02 04:59:03 +00:00
|
|
|
else { printf "OK: value is %d\n" v };
|
2024-04-18 14:06:28 +00:00
|
|
|
|
|
|
|
## --------------------------------------------------------------
|
|
|
|
|
|
|
|
class X | a b c d | {
|
|
|
|
fun :*new() {
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
fun x() {
|
|
|
|
a := 20 ; self.b:=(a + 10); c := (b + 20)
|
|
|
|
printf "%d %d %d\n" self.a self.b self.c
|
|
|
|
return (+ self.a self.b self.c)
|
|
|
|
}
|
|
|
|
fun y() {
|
|
|
|
self.d := (fun(k) {
|
|
|
|
return (k + 1)
|
|
|
|
})
|
|
|
|
return self.d
|
|
|
|
}
|
|
|
|
|
|
|
|
}; a := (X:new); v := (a:x)
|
|
|
|
if (nqv? v 100) { printf "ERROR: v is not 100\n" } \
|
|
|
|
else { printf "OK: value is %d\n" v }
|
|
|
|
|
|
|
|
v := ((a:y) 20);
|
|
|
|
if (nqv? v 21) { printf "ERROR: v is not 21\n" } \
|
|
|
|
else { printf "OK: value is %d\n" v }
|