2024-07-22 06:06:45 +00:00
|
|
|
class ##ERROR: syntax error - no class body
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
class B ##ERROR: syntax error - no class body
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
class B ( ##ERROR: syntax error - block expression expected as 'class' body
|
|
|
|
)
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
class B + ##ERROR: syntax error - prohibited binary operator - +
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
J := 11
|
|
|
|
class B {
|
|
|
|
if (J = 10) {
|
|
|
|
defun :*newA() {
|
|
|
|
return self
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
defun :*newB() {
|
|
|
|
return self
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
t2 := (B:newB)
|
|
|
|
t1 := (B:newA) ##ERROR: exception not handled - "unable to send newA to B - 'newA' not found in B"
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
class B [ x ] {
|
|
|
|
if (x > 0) { ##ERROR: syntax error - prohibited access to instance variable - x
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
---
|
|
|
|
|
2024-07-09 14:44:24 +00:00
|
|
|
class B [ x y ] {
|
2023-12-01 18:35:59 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2024-07-09 14:44:24 +00:00
|
|
|
class X :: B [ a b ] {
|
2024-05-26 14:18:26 +00:00
|
|
|
fun :* new(t) {
|
2023-12-01 18:35:59 +00:00
|
|
|
| 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;
|
|
|
|
};
|
|
|
|
|
2024-05-26 14:18:26 +00:00
|
|
|
fun print() {
|
2023-12-01 18:35:59 +00:00
|
|
|
self.c (+ self.a self.b);
|
|
|
|
printf "a=%d b=%d\n" self.a self.b;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2024-03-14 14:26:38 +00:00
|
|
|
|
|
|
|
---
|
|
|
|
|
2024-05-26 14:18:26 +00:00
|
|
|
class X {
|
|
|
|
fun :* xxx() {
|
2024-04-04 16:26:02 +00:00
|
|
|
return X;
|
|
|
|
}
|
2024-05-26 14:18:26 +00:00
|
|
|
fun :* qqq() {
|
2024-04-04 16:26:02 +00:00
|
|
|
return "hello"
|
|
|
|
}
|
|
|
|
|
2024-05-26 14:18:26 +00:00
|
|
|
fun String:length() { ##ERROR: syntax error - function name not valid
|
2024-04-04 16:26:02 +00:00
|
|
|
return (str.length self)
|
|
|
|
}
|
2024-03-14 14:26:38 +00:00
|
|
|
}
|
|
|
|
|
2024-04-04 16:26:02 +00:00
|
|
|
---
|
2024-05-26 14:18:26 +00:00
|
|
|
class X {
|
|
|
|
fun :* xxx() {
|
2024-04-04 16:26:02 +00:00
|
|
|
return X;
|
|
|
|
}
|
2024-05-26 14:18:26 +00:00
|
|
|
fun :* qqq() {
|
2024-04-04 16:26:02 +00:00
|
|
|
return "hello"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-05-29 14:19:25 +00:00
|
|
|
## this triggers a runtime error as J isn't a class name
|
|
|
|
fun J:ccc() { ##ERROR: exception not handled - "J accessed without initialization"
|
2024-04-04 16:26:02 +00:00
|
|
|
return 999
|
|
|
|
}
|
2024-05-26 14:18:26 +00:00
|
|
|
|
|
|
|
---
|
2024-05-29 14:19:25 +00:00
|
|
|
|
|
|
|
X := 20
|
|
|
|
|
|
|
|
## this also raises a runtime error as X isn't a class name
|
|
|
|
fun X:xxx() { ##ERROR: exception not handled - "not class"
|
|
|
|
return self
|
|
|
|
}
|
|
|
|
|
|
|
|
---
|
|
|
|
|
2024-05-26 14:18:26 +00:00
|
|
|
## 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() {
|
2024-05-29 14:19:25 +00:00
|
|
|
arr.put self 0 10 ##ERROR: exception not handled - "array index 0 out of bounds for array of size 0"
|
|
|
|
printf "%O" self
|
2024-05-26 14:18:26 +00:00
|
|
|
}
|
|
|
|
Array:boom
|
2024-05-29 14:19:25 +00:00
|
|
|
|
|
|
|
---
|
|
|
|
|
2024-07-09 14:44:24 +00:00
|
|
|
class X [ a b c ] {
|
2024-05-29 14:19:25 +00:00
|
|
|
fun :* new () {
|
|
|
|
self.a := 20
|
|
|
|
return self
|
|
|
|
}
|
|
|
|
|
|
|
|
fun getA() { return self.a }
|
|
|
|
}
|
|
|
|
|
|
|
|
## the instance variables are not accessible in out-of-class method
|
|
|
|
## defintionas there isn't a good way to know the class structure
|
|
|
|
## as X isn't known in advance and can point to anything
|
|
|
|
fun X:get_a() {
|
|
|
|
return self.a ##ERROR: syntax error - not allowed to prefix with self
|
|
|
|
}
|
|
|
|
|
|
|
|
printf "%d\n" ((X:new):get_a)
|
|
|
|
|
|
|
|
---
|
|
|
|
|
2024-07-09 14:44:24 +00:00
|
|
|
class F [ a b c ] {
|
2024-05-29 14:19:25 +00:00
|
|
|
}
|
|
|
|
|
2024-07-09 14:44:24 +00:00
|
|
|
class X [ a b c ] {
|
2024-05-29 14:19:25 +00:00
|
|
|
fun oh() {
|
|
|
|
fun F:get_a() {
|
|
|
|
return super.a ##ERROR: syntax error - not allowed to prefix with super
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|