65 lines
1.0 KiB
Plaintext
65 lines
1.0 KiB
Plaintext
class B | x y | {
|
|
|
|
};
|
|
|
|
class X :: B | a b | {
|
|
fun :* new(t) {
|
|
| a |
|
|
set self.a t;
|
|
set a 100;
|
|
set self.b (* t 2);
|
|
|
|
set self.c (fun(b) { ##ERROR: syntax error - unknown class-level variable name
|
|
printf "xxxx [%d]\n" b;
|
|
});
|
|
return self;
|
|
};
|
|
|
|
fun print() {
|
|
self.c (+ self.a self.b);
|
|
printf "a=%d b=%d\n" self.a self.b;
|
|
}
|
|
};
|
|
|
|
|
|
---
|
|
|
|
class X {
|
|
fun :* xxx() {
|
|
return X;
|
|
}
|
|
fun :* qqq() {
|
|
return "hello"
|
|
}
|
|
|
|
fun String:length() { ##ERROR: syntax error - function name not valid
|
|
return (str.length self)
|
|
}
|
|
}
|
|
|
|
---
|
|
class X {
|
|
fun :* xxx() {
|
|
return X;
|
|
}
|
|
fun :* qqq() {
|
|
return "hello"
|
|
}
|
|
}
|
|
|
|
## this will trigger a runtime error as J isn't a class name
|
|
fun J:ccc() { ##ERROR: exception not handled
|
|
return 999
|
|
}
|
|
|
|
---
|
|
## this must not be very useful as Array is an index item
|
|
## and the clase instantiation method can't specify the size
|
|
## you can't place an item in the arrya at all.
|
|
|
|
fun Array:*boom() {
|
|
arr.put self 0 10 ##ERROR: exception not handled
|
|
printf "%O" self
|
|
}
|
|
Array:boom
|