## Παρασκευή, 23 Μαρτίου 2018

### Revision 3 (Version 9.2) Operators and Light Events for Groups

Revision 3 for Version 9.2 remove a bug in events, and has two implementations, one for operators in groups (a better code, and use of priorities)

1) New extension for operators, using unary, and priorities (low standard, High for * and /), and we can define a right operator for higher priority, and this used for power.
Comparison Operators are always lower priority, and return boolean value (not Group). All other operators return group. Here group has one value (just a public variable), so we can check the evaluation easy.

group alfa {
n=10
operator unary {
.n-!
}
operator "-" {
.n-=b.n
}
operator "=" {
push .n=b.n
}
operator ">" {
push .n>b.n
}
operator "<" {
push .n<b.n
}
operator  "+" {
.n+=b.n
}
operator right "**" {
.n<=.n**b.n
}
operator high "*" {
.n*=b.n
}
operator high "/" {
.n/=b.n
}
Function Bigger {
call operator ">", group
=Number
}

module operations {
call operator "+", z
call operator "+", z
call operator "*", z
call operator "-", z
m=z
m.n=100
call operator "/", m
}
}

Group Alfa {
operator "/" {
.n/=b.n
}
}
z=alfa
k=alfa
k.n=2
z.n=30
m=alfa**k**k+z**k
Print alfa.n**k.n**k.n+z.n**k.n
Print m.n
m=-alfa/-k*-z
Print -z.n*-alfa.n/-k.n
Print m.n
m=alfa*z+alfa*z+z
Print m.n ',  z*ALFA+alfa*z+z>z and 10>2  ' try this
Print alfa.n*z.n+alfa.n*z.n+z.n
Print alfa.n*z.n+alfa.n*z.n+z.n
m=(alfa+z+z)*z
Print m.n, "=(alfa+z+z)*z"
Print (alfa.n+z.n+z.n)*z.n
m=z*(alfa+z+z)
Print m.n, "=z*(alfa+z+z)"
Print z.n*(alfa.n+z.n+z.n)
Print alfa.n
alfa.operations z
Print alfa.n, z.n
alfa*z
Print alfa.n, z.n
alfa-z
Print alfa.n, z.n
m=alfa-z
Print m.n
Print alfa.bigger(z), alfa>z
m=m/z
Print m.n, z.n

2)Light Events for groups:
Group WithEvents Alfa {
Events "a", "b"
Χ=10
Module Check {
Def M as long
call event "a", &M, 20
Print stack.size, M
}
Module CheckB(what\$) {
call event "b", what\$
}
}
M=100
a=500
b=4000
Function Alfa_a(New &a,b) {
M++
a=M
Print "ok", a, b, M
push 500 ' can't return using stack, stack is private
}
Function Alfa_b(a\$) {
Print "From Event:";a\$
}
Alfa.Check
Stack ' print empty line, stack is empty
dim k(10)=alfa
Module Z (M()){
For i=0 to 9{
For M(i) {
.check
}
}
M(5).checkb "This is M(5)"
}
Z K()
Beta=k(3)
Beta.checkb "Hello There"
Print a, b ' not changed

The same ouput can we have using Event objects. Event objects have commands like these
Event A Hold
Event A Clear
Event A Release
Event A New aaa() [, bbb()]   ' we can bind some functions for multicast purposes
Event A Drop aaa() [, bbb()] ' we can drop any function
Also These events need to have a signature using a Read command, without "as type". Only the number and kind (by reference using &, \$ for strings, ( ) for arrays)
So in Event A variable b can be a number or an object.
In function Alfa_a we have to place New because events call functions as code in module where the function belong, so we have same scope, a New in front in parameter list means Read New &a, b

Group Alfa {
Event A {
}
Event B {
}
Χ=10
Module Check {
Def M as long
call event .A, &M, 20
Print stack.size, M
}
Module CheckB (what\$) {
call event .B, what\$
}
}
M=100
a=500
b=4000
Function Alfa_a(New &a, b as long) {
M++
a=M
Print "ok", a, b, M
push 500 ' can't return using stack, stack is private
}
Function Alfa_b(New zz\$) {
Print "From Event:";zz\$
}

Event Alfa.A New Lazy\$(&Alfa_a())
Event Alfa.B New Lazy\$(&Alfa_b())
Alfa.Check
Stack ' print empty line, stack is empty
dim k(10)=alfa
Module Z (M()){
For i=0 to 9{
For M(i) {
.check
}
}
M(5).checkb "This is M(5)"
}
Z K()
Beta=k(3)
Beta.checkb "Hello There"
Print a, b ' not changed